Hello andreip,

I'd like you to do a code review.  Please execute
        g4 diff -c 9464280

or point your web browser to
        http://mondrian/9464280

to review the following code:

Change 9464280 by stevebl...@steveblock-gears3 on 2008/12/18 12:45:35 *pending*

        Changes to JavaScript interface required for Opera.
        
        R=andreip
        [email protected],[email protected]
        DELTA=106  (103 added, 0 deleted, 3 changed)
        OCL=9464280

Affected files ...

... //depot/googleclient/gears/opensource/gears/base/common/js_runner.h#20 edit
... //depot/googleclient/gears/opensource/gears/base/common/js_runner_np.cc#31 
edit
... //depot/googleclient/gears/opensource/gears/base/common/js_types.cc#52 edit
... //depot/googleclient/gears/opensource/gears/base/common/js_types.h#39 edit

106 delta lines: 103 added, 0 deleted, 3 changed

Also consider running:
        g4 lint -c 9464280

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 9464280 by stevebl...@steveblock-gears3 on 2008/12/18 12:45:35 *pending*

        Changes to JavaScript interface required for Opera.

Affected files ...

... //depot/googleclient/gears/opensource/gears/base/common/js_runner.h#20 edit
... //depot/googleclient/gears/opensource/gears/base/common/js_runner_np.cc#31 
edit
... //depot/googleclient/gears/opensource/gears/base/common/js_types.cc#52 edit
... //depot/googleclient/gears/opensource/gears/base/common/js_types.h#39 edit

==== //depot/googleclient/gears/opensource/gears/base/common/js_runner.h#20 - 
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/common/js_runner.h 
====
# action=edit type=text
--- googleclient/gears/opensource/gears/base/common/js_runner.h 2008-12-18 
12:47:08.000000000 +0000
+++ googleclient/gears/opensource/gears/base/common/js_runner.h 2008-12-18 
12:45:35.000000000 +0000
@@ -98,6 +98,10 @@
   virtual bool Start(const std::string16 &full_script) = 0;
   virtual bool Stop() = 0;
   virtual JsContextPtr GetContext() = 0;
+  // Only used by opera. Set an object which can be used to identify the
+  // current thread so it can be run in the correct context
+  virtual void SetThreadIdentifier(){}
+  virtual void ClearThreadIdentifier(){}
   virtual bool Eval(const std::string16 &script) = 0;
   virtual void SetErrorHandler(JsErrorHandlerInterface *error_handler) = 0;
 
@@ -244,6 +248,9 @@
 // successfully initialize to a stable but unusable state.
 JsRunnerInterface* NewJsRunner(JSRuntime *js_runtime);
 #else
+#ifdef BROWSER_OPERA
+JsRunnerInterface* NewJsRunner(JsContextPtr context, void* object);
+#endif  // BROWSER_OPERA
 JsRunnerInterface* NewJsRunner();
 #endif
 
==== //depot/googleclient/gears/opensource/gears/base/common/js_runner_np.cc#31 
- 
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/common/js_runner_np.cc
 ====
# action=edit type=text
--- googleclient/gears/opensource/gears/base/common/js_runner_np.cc     
2008-12-18 12:47:08.000000000 +0000
+++ googleclient/gears/opensource/gears/base/common/js_runner_np.cc     
2008-12-18 12:45:38.000000000 +0000
@@ -52,6 +52,10 @@
 #include "gears/base/npapi/module_wrapper.h"
 #include "gears/base/npapi/np_utils.h"
 #include "gears/base/npapi/scoped_npapi_handles.h"
+#ifdef BROWSER_OPERA
+#include "gears/base/opera/opera_utils.h"
+#include "third_party/opera/opera_callback_api.h"
+#endif  // BROWSER_OPERA
 #ifdef BROWSER_WEBKIT
 #include "gears/base/safari/npapi_patches.h" 
 #endif
@@ -216,8 +220,10 @@
 
     // Invoke the method.
     ScopedNPVariant result;
+       SetThreadIdentifier();
     bool rv = NPN_InvokeDefault(GetContext(), evaluator,
                                 evaluator_args.get(), evaluator_argc, &result);
+       ClearThreadIdentifier();
     if (!rv) { return false; }
 
     if (!NPVARIANT_IS_OBJECT(result)) {
@@ -269,7 +275,10 @@
 
     NPString np_script = {script_utf8.data(), script_utf8.length()};
     ScopedNPVariant result;
-    if (!NPN_Evaluate(GetContext(), global_object, &np_script, &result))
+       SetThreadIdentifier();
+    bool rv = NPN_Evaluate(GetContext(), global_object, &np_script, &result);
+       ClearThreadIdentifier();
+       if (!rv)
       return false;
 
     if (catch_exceptions && NPVARIANT_IS_STRING(result)) {
@@ -474,8 +483,10 @@
     NPObject *global = GetGlobalObject();
     NPString np_script = { kEvaluatorScript, ARRAYSIZE(kEvaluatorScript) - 1};
     ScopedNPVariant evaluator;
-    if (!NPN_Evaluate(GetContext(), global, &np_script, &evaluator) ||
-        !NPVARIANT_IS_OBJECT(evaluator)) {
+       SetThreadIdentifier();
+       bool rv = NPN_Evaluate(GetContext(), global, &np_script, &evaluator);
+       ClearThreadIdentifier();
+    if (!rv || !NPVARIANT_IS_OBJECT(evaluator)) {
       assert(false);
       return NULL;
     }
@@ -495,7 +506,9 @@
     // Evaluate javascript code: 'ConstructorName()'
     NPString script = {string_to_eval.c_str(), string_to_eval.length()};
     ScopedNPVariant object;
+       SetThreadIdentifier();
     bool rv = NPN_Evaluate(GetContext(), global_object, &script, &object);
+       ClearThreadIdentifier();
     if (!rv) {
       LOG(("Could not invoke object constructor."));
       return NULL;
@@ -624,6 +637,75 @@
   DISALLOW_EVIL_CONSTRUCTORS(JsRunner);
 };
 
+#ifdef BROWSER_OPERA
+// This class is a stub that is used to present a uniform interface to
+// common functionality to both workers and the main thread.
+class OperaJsRunner : public JsRunnerBase {
+ public:
+  OperaJsRunner(NPP instance, void* object)
+      : np_instance_(instance), global_object_((NPObject*)object) {
+  }
+
+  virtual ~OperaJsRunner() {
+    // Alert modules that the engine is unloading.
+    SendEvent(JSEVENT_UNLOAD);
+    
+    Cleanup();
+    //NPN_ReleaseObject(global_object_);
+  }
+
+  virtual void OnModuleEnvironmentAttach() { };
+  virtual void OnModuleEnvironmentDetach() { };
+
+  NPObject *GetGlobalObject() {
+    return global_object_;
+  }
+
+  JsContextPtr GetContext() {
+    return np_instance_;
+  }
+
+  virtual void SetThreadIdentifier(){
+         
OperaUtils::GetBrowserApiForGears()->SetCurrentGlobalObject(np_instance_, 
global_object_);
+  }
+  virtual void ClearThreadIdentifier(){
+         
OperaUtils::GetBrowserApiForGears()->SetCurrentGlobalObject(np_instance_, NULL);
+  }
+
+  bool Start(const std::string16 &full_script) {
+    assert(false); // Should not be called on the OperaJsRunner.
+    return false;
+  }
+
+  bool Stop() {
+    assert(false); // Should not be called on the OperaJsRunner.
+    return false;
+  }
+  
+#ifdef DEBUG
+  void ForceGC() {
+    // TODO(timj): implement for opera worker threads.
+  }
+#endif
+
+  bool Eval(const std::string16 &script) {
+    return EvalImpl(script, true);
+  }
+
+  void SetErrorHandler(JsErrorHandlerInterface *handler) {
+    assert(false); // Should not be called on the OperaJsRunner.
+  }
+
+  virtual void ThrowGlobalError(const std::string16 &message) {
+         std::string16 script = STRING16(L"throw new Error('") + 
EscapeMessage(message) + STRING16(L"');");
+         EvalImpl(script, false);
+  }
+ private:
+  NPP np_instance_;
+  NPObject *global_object_;
+  DISALLOW_EVIL_CONSTRUCTORS(OperaJsRunner);
+};
+#endif // BROWSER_OPERA
 
 // This class is a stub that is used to present a uniform interface to
 // common functionality to both workers and the main thread.
@@ -735,6 +817,12 @@
   }
 }
 
+#ifdef BROWSER_OPERA
+JsRunnerInterface *NewJsRunner(JsContextPtr context, void* object) {
+  return static_cast<JsRunnerInterface *>(new OperaJsRunner(context, object));
+}
+#endif // BROWSER_OPERA
+
 JsRunnerInterface *NewJsRunner() {
   return static_cast<JsRunnerInterface *>(new JsRunner());
 }
==== //depot/googleclient/gears/opensource/gears/base/common/js_types.cc#52 - 
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/common/js_types.cc 
====
# action=edit type=text
--- googleclient/gears/opensource/gears/base/common/js_types.cc 2008-11-20 
17:26:07.000000000 +0000
+++ googleclient/gears/opensource/gears/base/common/js_types.cc 2008-12-18 
12:45:41.000000000 +0000
@@ -2376,11 +2376,16 @@
   if (!String16ToUTF8(message.data(), message.length(), &message_utf8))
     message_utf8 = "Unknown Gears Error";  // better to throw *something*
 
+#ifdef BROWSER_OPERA
+  // set the exception on the plugin object instead of the window
+  NPN_SetException(js_object(), message_utf8.c_str());
+#else  // BROWSER_OPERA
   NPObject *window;
   if (NPN_GetValue(js_context(), NPNVWindowNPObject, &window) != 
NPERR_NO_ERROR)
     return;
   ScopedNPObject window_scoped(window);
   NPN_SetException(window, message_utf8.c_str());
+#endif  // BROWSER_OPERA
 }
 
 #endif
==== //depot/googleclient/gears/opensource/gears/base/common/js_types.h#39 - 
c:\MyDocs\Gears3/googleclient/gears/opensource/gears/base/common/js_types.h ====
# action=edit type=text
--- googleclient/gears/opensource/gears/base/common/js_types.h  2008-11-10 
14:29:57.000000000 +0000
+++ googleclient/gears/opensource/gears/base/common/js_types.h  2008-12-18 
12:45:43.000000000 +0000
@@ -544,6 +544,9 @@
 #if BROWSER_FF
   JsRunnerInterface *js_runner() { return js_runner_; }
 #endif
+#if BROWSER_NPAPI
+  NPObject *js_object() { return object_; }
+#endif  // BROWSER_NPAPI
 
  private:
   int GetArgumentCount();

Reply via email to