~cmiller/unity-chromium-extension/extension-dir

« back to all changes in this revision

Viewing changes to chromium-extension/unity-webapps-binding.js

  • Committer: Tarmac
  • Author(s): Alexandre Abreu
  • Date: 2013-07-08 15:04:14 UTC
  • mfrom: (224.1.1 fix-chromium-28-support)
  • Revision ID: tarmac-20130708150414-2krskytsa61xd6v7
Tags: BRANCH_13_04
[Impact]

Workaround for an issue with Chromium 27 and 28 and Webapps. Webapps stopped working altogether with those chromium versions. What happened is that any javascript callback function that was called (whatever the stage) from chromium's internal could not access the NPAPI plugin variable (_uwa) that is a javascript object that is a bridge to the WebApps NPAPI plugin. Accessing the variable throws with an exception "NPObject has been deleted" (which is not the case).

The workaround rebinds the variable for every callback to the plugin node.

TECHNICAL DETAILS:
-----------------

There has been some changes recently in chromium 27+ around the v8 bindings' templates separated by world type (either page world or content script private world). Although I am not sure, it seemed to have an impact somewhere in the lookup location for V8NPObject v8 binding variables.

The "NPOBJect has been deleted" exception first occurs when webapps callback in the context_prepare() callback (from a native NPAPI function) that tries to call the plugin using _uwa. The variable is just closed over in the callback but is being looked up in the v8 binding for NPAPI (npObjectInvokeImpl() in WebCore/bindings/v8/V8NPObject.cpp) in the wrong World (page world instead of content script world).

The V8NPObject binding for the NPAPI plugin is apparently created properly (tagged w/ the proper world id) but somewhere along the line (copying?) something goes wrong.

[Test Case]

1. install the unity-chromium-extension,
2. open chromium 28 and make sure that the extension is properly detected (chrome://extensions),
3. go to e.g. facebook.com or bbc.co.uk./news,
4. make sure that a launcher icon appears and the webapps integrates (notifications for bbc and messaging menu for facebook),

[Regression Potential]

None since the fix is strictly confined in the webapps extension and webapps are currently broken.

Approved by PS Jenkins bot, Víctor R. Ruiz.

Show diffs side-by-side

added added

removed removed

Lines of Context:
127
127
 
128
128
 
129
129
UnityGlobalPropertyInitializer = {
130
 
  makeCallback: function (uwa, service, logger) {
 
130
  makeCallback: function (get_uwa, service, logger) {
131
131
    function callback(aWindow) {
132
132
      var _global = {
133
133
        context: null
134
134
      };
135
 
      var _uwa = uwa;
136
 
      
 
135
      var _uwa = get_uwa();
 
136
 
137
137
      // TODO fix, improper "form"
138
138
      var PopupManager = UnityPopupManager;
139
139
      var WindowHelper = new UnityWindowHelper (window);
149
149
            if (request && request.method && request.method === 'on_tab_active_changed') {
150
150
              UnityContentScriptApi.getTabInfo (
151
151
                function (response) {
 
152
                  var uwa = get_uwa();
152
153
                  if (request.tabId === response.tabId) {
153
154
                    logger ('Activating context corresponding to tab ' + request.tabId);
154
 
                    _uwa.context_set_view_is_active (_global.context, 1);
 
155
                    uwa.context_set_view_is_active (_global.context, 1);
155
156
                  }
156
157
                  else {
157
 
                    _uwa.context_set_view_is_active (_global.context, 0);
 
158
                    uwa.context_set_view_is_active (_global.context, 0);
158
159
                  }
159
160
                });
160
161
            }
163
164
 
164
165
      window.addEventListener("pagehide"
165
166
                              , function(event) {
 
167
                                var uwa = get_uwa();
166
168
                                if (_global.context == null) {return;}
167
 
                                _uwa.context_destroy (_global.context, 0);
 
169
                                uwa.context_destroy (_global.context, 0);
168
170
                                _global.context = null;
169
171
                              }, false);
170
172
      _global.onInitCallbacks = [];
201
203
        
202
204
        var contextPrepared = function () {
203
205
 
 
206
          var uwa = get_uwa();
 
207
 
204
208
          if (login) {
205
209
            logger("Notifying parent extension of login info");
206
210
            chrome.extension.sendMessage ({
242
246
          
243
247
          _global.contextReady = true;
244
248
          
245
 
          _uwa.context_add_icon (_global.context
 
249
          uwa.context_add_icon (_global.context
246
250
                                 , UnityFaviconUtils.getFaviconForDocument (document)
247
251
                                 , 16);
248
252
          
249
 
          _uwa.context_on_raise_callback (_global.context, appRaiseCallback, null);
250
 
          _uwa.context_on_close_callback (_global.context, appCloseCallback, null);
251
 
          _uwa.context_set_preview_requested_callback (_global.context, previewRequestedCallback, null);
 
253
          uwa.context_on_raise_callback (_global.context, appRaiseCallback, null);
 
254
          uwa.context_on_close_callback (_global.context, appCloseCallback, null);
 
255
          uwa.context_set_preview_requested_callback (_global.context, previewRequestedCallback, null);
252
256
          
253
257
          if ((homepage != undefined) && (homepage != null)) {
254
 
            _uwa.context_set_homepage (_global.context, homepage);
 
258
            uwa.context_set_homepage (_global.context, homepage);
255
259
          }
256
260
          
257
261
          for (var c in _global.onInitCallbacks) {
271
275
          
272
276
          doListenToTabChanges ();
273
277
 
274
 
          _uwa.context_set_view_is_active (_global.context, 1);
 
278
          uwa.context_set_view_is_active (_global.context, 1);
275
279
 
276
 
          _uwa.context_set_view_location (_global.context, document.location.toString());
277
 
          _uwa.service_set_xid_for_browser_window_id (service
 
280
          uwa.context_set_view_location (_global.context, document.location.toString());
 
281
          uwa.service_set_xid_for_browser_window_id (service
278
282
                                                      , _global.context
279
283
                                                      , environmentInfos.windowId);
280
284
          
281
 
          var context_name = _uwa.context_get_name(_global.context);
282
 
          var domain_name = _uwa.context_get_domain(_global.context) || domain;
283
 
          var interest_id = _uwa.context_get_interest_id(_global.context);
 
285
          var context_name = uwa.context_get_name(_global.context);
 
286
          var domain_name = uwa.context_get_domain(_global.context) || domain;
 
287
          var interest_id = uwa.context_get_interest_id(_global.context);
284
288
          UnityContentScriptApi.addIntegrationScriptForTab(context_name
285
289
                                                           , domain_name
286
290
                                                           , interest_id);
427
431
      };
428
432
 
429
433
      function acceptData(context, mimes, func) {
 
434
        var uwa = get_uwa();
430
435
        uwa.context_set_application_accept_data(_global.context, mimes);
431
436
        _global.acceptDataCallback = func;
432
437
      }
433
438
 
434
439
      function contextAddApplicationActions(actions) {
 
440
        var uwa = get_uwa();
435
441
        var appActions = [];
436
442
        for (var i = 0; i < actions.length; i++) {
437
443
          appActions.push({
448
454
                      , unityPrepareEnvironment
449
455
                      , UnityContentScriptApi.toDataURL
450
456
                      , logger
451
 
                      , _uwa
 
457
                      , get_uwa
452
458
                      , _global
453
459
                      , CallbackManager
454
460
                      , acceptData);