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

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: fix comments 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 internalIframeElement = privates(view).internalElement;
18 if (internalIframeElement)
19 return internalIframeElement.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 // Check the current state.
74 if (!this.checkState('create')) {
75 this.handleCallback(callback);
76 return;
77 }
78
79 // Callback wrapper function to store the guestInstanceId from the
80 // createGuest() callback, handle potential creation failure, and advance the
81 // queue.
82 var callbackWrapper = function(callback, guestInfo) {
83 this.id = guestInfo.id;
84
85 // Check if creation failed.
86 if (this.id === 0) {
87 this.state = GuestViewImpl.GuestState.GUEST_STATE_START;
88 this.contentWindow = null;
89 }
90
91 ResizeEvent.addListener(this.callOnResize, {instanceId: this.id});
92 this.handleCallback(callback);
93 };
94
95 this.sendCreateRequest(createParams, callbackWrapper.bind(this, callback));
96
97 this.state = GuestViewImpl.GuestState.GUEST_STATE_CREATED;
98 };
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698