************************* G4 reminder *************************
These new files:
c:\MyDocs\Gears3\googleclient\gears\opensource\gears\base\opera\opera_utils.cc
are missing unit tests.
***************************************************************
Hello andreip,
I'd like you to do a code review. Please execute
g4 diff -c 9350686
or point your web browser to
http://mondrian/9350686
to review the following code:
Change 9350686 by stevebl...@steveblock-gears3 on 2008/12/10 17:30:09 *pending*
Adds OperaUtils.
R=andreip
[email protected],[email protected]
DELTA=213 (213 added, 0 deleted, 0 changed)
OCL=9350686
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#220 edit
... //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.cc#1 add
... //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.h#1 add
213 delta lines: 213 added, 0 deleted, 0 changed
Also consider running:
g4 lint -c 9350686
which verifies that the changelist doesn't introduce new style violations.
If you can't do the review, please let me know as soon as possible. During
your review, please ensure that all new code has corresponding unit tests and
that existing unit tests are updated appropriately. Visit
http://www/eng/code_review.html for more information.
This is a semiautomated message from "g4 mail". Complaints or suggestions?
Mail [email protected].
Change 9350686 by stevebl...@steveblock-gears3 on 2008/12/10 17:30:09 *pending*
Adds OperaUtils.
R=andreip
[email protected],[email protected]
DELTA=201 (201 added, 0 deleted, 0 changed)
OCL=9350686
Affected files ...
... //depot/googleclient/gears/opensource/gears/Makefile#220 edit
... //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.cc#1 add
... //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.h#1 add
==== //depot/googleclient/gears/opensource/gears/Makefile#220 -
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/Makefile ====
# action=edit type=text
--- googleclient/gears/opensource/gears/Makefile 2008-12-12
14:22:25.000000000 +0000
+++ googleclient/gears/opensource/gears/Makefile 2008-12-12
13:44:48.000000000 +0000
@@ -1200,6 +1200,7 @@
detect_version_collision_win32.cc \
message_queue_win32.cc \
js_standalone_engine_op.cc \
+ opera_utils.cc \
paths_op.cc \
$(NULL)
==== //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.cc#1 -
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/opera/opera_utils.cc
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/base/opera/opera_utils.cc
2008-12-12 15:19:24.000000000 +0000
@@ -0,0 +1,146 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
notice,
+// this list of conditions and the following disclaimer in the
documentation
+// and/or other materials provided with the distribution.
+// 3. Neither the name of Google Inc. nor the names of its contributors may be
+// used to endorse or promote products derived from this software without
+// specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+
+#include "gears/base/opera/opera_utils.h"
+
+#include <assert.h>
+
+#include "gears/base/npapi/module_wrapper.h"
+#include "gears/factory/factory_impl.h"
+#include "gears/factory/factory_np.h"
+#include "gears/ui/common/settings_dialog.h"
+#include "third_party/opera/opera_callback_api.h"
+#include "third_party/opera/opera_worker_interface.h"
+
+
+// Implementation of the wrapper class for the native opera worker threads
+class OperaWorkerThreadImpl : public OperaWorkerThreadInterface {
+public:
+ OperaWorkerThreadImpl() : js_runner_(NULL) {
+ factory_.reset(NULL);
+ }
+
+ virtual ~OperaWorkerThreadImpl() {
+ factory_.reset(NULL);
+ delete js_runner_;
+ }
+
+ virtual void Destroy() {
+ delete this;
+ }
+
+ virtual NPObject *CreateWorkerFactory(NPP instance,
+ NPObject *global_object,
+ const unsigned short* url) {
+ if (!js_runner_) {
+ // TODO([email protected]): Add required overload of NewJsRunner().
+ //js_runner_ = NewJsRunner(instance, global_object);
+ assert(false);
+ }
+ if (!js_runner_)
+ return NULL;
+
+ if (!factory_.get()) {
+ SecurityOrigin security_origin;
+ scoped_refptr<BrowsingContext> browsing_context;
+ if (!security_origin.InitFromUrl(url))
+ return NULL;
+ BrowserUtils::GetPageBrowsingContext(instance, &browsing_context);
+
+ ModuleEnvironment *module_env =
+ new ModuleEnvironment(security_origin,
+ true, // is_worker
+ js_runner_,
+ browsing_context.get());
+ if (!module_env)
+ return NULL;
+
+ if (!CreateModule<GearsFactoryImpl>(
+ module_env,
+ reinterpret_cast<JsCallContext*>(instance),
+ &factory_)) {
+ return NULL;
+ }
+ }
+
+ if (!NPVARIANT_IS_OBJECT(factory_.get()->GetWrapperToken()))
+ return NULL;
+ NPObject *factory_object =
+ NPVARIANT_TO_OBJECT(factory_.get()->GetWrapperToken());
+ NPN_RetainObject(factory_object);
+
+ return factory_object;
+ }
+
+ virtual void SuspendObjectCreation() {
+ if (factory_.get())
+ factory_.get()->SuspendObjectCreation();
+ }
+
+ virtual void ResumeObjectCreationAndUpdatePermissions() {
+ if (factory_.get())
+ factory_.get()->ResumeObjectCreationAndUpdatePermissions();
+ }
+
+ private:
+ JsRunnerInterface *js_runner_;
+ scoped_refptr<GearsFactoryImpl> factory_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(OperaWorkerThreadImpl);
+};
+
+// static
+OperaGearsAPI* OperaUtils::opera_api_ = NULL;
+// static
+ThreadId OperaUtils::browser_thread_ = 0;
+
+//static
+void OperaUtils::Init(OperaGearsAPI *opera_api, ThreadId browser_thread) {
+ opera_api_ = opera_api;
+ browser_thread_ = browser_thread;
+}
+
+// static
+OperaGearsAPI* OperaUtils::GetBrowserApiForGears() {
+ assert(opera_api_ != NULL);
+ return opera_api_;
+}
+
+// static
+ThreadId OperaUtils::GetBrowserThreadId() {
+ assert(browser_thread_ != NULL);
+ return browser_thread_;
+}
+
+// static
+OperaWorkerThreadInterface* OperaUtils::CreateWorkerThread() {
+ OperaWorkerThreadImpl *worker_thread = new OperaWorkerThreadImpl();
+ return worker_thread;
+}
+
+// static
+void OperaUtils::OpenSettingsDialog() {
+ SettingsDialog::Run(NULL);
+}
==== //depot/googleclient/gears/opensource/gears/base/opera/opera_utils.h#1 -
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/opera/opera_utils.h
====
# action=add type=text
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ googleclient/gears/opensource/gears/base/opera/opera_utils.h
2008-12-12 14:53:21.000000000 +0000
@@ -0,0 +1,66 @@
+// Copyright 2008, Google Inc.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions are met:
+//
+// 1. Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+// 2. Redistributions in binary form must reproduce the above copyright
notice,
+// this list of conditions and the following disclaimer in the
documentation
+// and/or other materials provided with the distribution.
+// 3. Neither the name of Google Inc. nor the names of its contributors may be
+// used to endorse or promote products derived from this software without
+// specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
+// WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
+// MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO
+// EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
+// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
+// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
+// OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
+// WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+// OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
+// ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+//
+// This class contains convenience functions used by the Opera implementation
+// of the plugin. It holds the pointer to the API exported by Opera.
+//
+
+#ifndef GEARS_BASE_OPERA_OPERA_UTILS_H__
+#define GEARS_BASE_OPERA_OPERA_UTILS_H__
+
+#include "gears/base/common/message_queue.h" // for ThreadId
+
+class OperaGearsAPI;
+class OperaWorkerThreadInterface;
+
+class OperaUtils {
+ public:
+ // Called by Opera when it first loads Gears. opera_api points to an object
+ // that implements the Opera API for Gears. browser_thread must be
+ // set to the ID of the thread Opera runs on.
+ static void Init(OperaGearsAPI *opera_api, ThreadId browser_thread);
+
+ // Returns the pointer to the Opera API for Gears.
+ static OperaGearsAPI *GetBrowserApiForGears();
+
+ // Returns the ID of the thread the browser runs on.
+ static ThreadId GetBrowserThreadId();
+
+ // Creates and returns a handle to an Opera worker thread.
+ static OperaWorkerThreadInterface *CreateWorkerThread();
+
+ // Called to open the Gears settings dialog.
+ static void OpenSettingsDialog();
+
+ private:
+ // Holds the pointer to the global Opera API for Gears.
+ static OperaGearsAPI *opera_api_;
+ // Holds the ID of the thread the browser runs on.
+ static ThreadId browser_thread_;
+
+ DISALLOW_EVIL_CONSTRUCTORS(OperaUtils);
+};
+
+#endif // GEARS_BASE_OPERA_OPERA_UTILS_H__