Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(167)

Side by Side Diff: extensions/renderer/resources/guest_view/guest_view_iframe.js

Issue 1165773004: Extract the element implementation logic to function mods in <webview>. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@qui
Patch Set: Clean up Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2015 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // --site-per-process overrides for guest_view.js.
6
7 var GuestView = require('guestView').GuestView;
8 var GuestViewImpl = require('guestView').GuestViewImpl;
9 var GuestViewInternalNatives = requireNative('guest_view_internal');
10 var ResizeEvent = require('guestView').ResizeEvent;
11
12 var getIframeContentWindow = function(viewInstanceId) {
13 var view = GuestViewInternalNatives.GetViewFromID(viewInstanceId);
14 if (!view)
15 return null;
16
17 var internalElement = privates(view).browserPluginElement;
Fady Samuel 2015/06/05 23:45:53 Renane browserPluginElement to internalElement.
lazyboy 2015/06/05 23:52:37 Done.
18 if (internalElement)
19 return internalElement.contentWindow;
20
21 return null;
22 };
23
24 // Internal implementation of attach().
25 GuestViewImpl.prototype.attachImpl$ = function(
26 internalInstanceId, viewInstanceId, attachParams, callback) {
27 // Check the current state.
28 if (!this.checkState('attach')) {
29 this.handleCallback(callback);
30 return;
31 }
32
33 // Callback wrapper function to store the contentWindow from the attachGuest()
34 // callback, handle potential attaching failure, register an automatic detach,
35 // and advance the queue.
36 var callbackWrapper = function(callback, contentWindow) {
37 // Check if attaching failed.
38 contentWindow = getIframeContentWindow(viewInstanceId);
39 if (!contentWindow) {
40 this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
41 this.internalInstanceId = 0;
42 } else {
43 // Only update the contentWindow if attaching is successful.
44 this.contentWindow = contentWindow;
45 }
46
47 this.handleCallback(callback);
48 };
49
50 attachParams['instanceId'] = viewInstanceId;
51 var contentWindow = getIframeContentWindow(viewInstanceId);
52 // TODO(lazyboy): Call binding function to attach this guest.
53 // |contentWindow| should be used to retrieve the RenderFrame in cpp.
54
55 this.internalInstanceId = internalInstanceId;
56 this.state = GuestViewImpl.GuestState.GUEST_STATE_ATTACHED;
57
58 // Detach automatically when the container is destroyed.
59 GuestViewInternalNatives.RegisterDestructionCallback(
60 internalInstanceId, this.weakWrapper(function() {
61 if (this.state != GuestViewImpl.GuestState.GUEST_STATE_ATTACHED ||
62 this.internalInstanceId != internalInstanceId) {
63 return;
64 }
65
66 this.internalInstanceId = 0;
67 this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
68 }, viewInstanceId));
69 };
70
71 // Internal implementation of create().
72 GuestViewImpl.prototype.createImpl$ = function(createParams, callback) {
73 window.console.log('GuestViewImpl.prototype.createImpl$');
Fady Samuel 2015/06/05 23:45:53 Avoid spew.
lazyboy 2015/06/05 23:52:37 Done.
74 // Check the current state.
75 if (!this.checkState('create')) {
76 this.handleCallback(callback);
77 return;
78 }
79
80 // Callback wrapper function to store the guestInstanceId from the
81 // createGuest() callback, handle potential creation failure, and advance the
82 // queue.
83 var callbackWrapper = function(callback, guestInfo) {
84 this.id = guestInfo.id;
85
86 // Check if creation failed.
87 if (this.id === 0) {
88 this.state = GuestViewImpl.GuestState.GUEST_STATE_START;
89 this.contentWindow = null;
90 }
91
92 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id});
93 this.handleCallback(callback);
94 };
95
96 this.sendCreateRequest(createParams, callbackWrapper.bind(this, callback));
97
98 this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
99 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698