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

Side by Side Diff: chrome/browser/guestview/webview/webview_guest.cc

Issue 23514016: <webview>: Cleanup WebRequest event listeners when embedder destroyed (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed WebRequest unit test Created 7 years, 3 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
« no previous file with comments | « chrome/browser/guestview/webview/webview_guest.h ('k') | chrome/chrome_renderer.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/guestview/webview/webview_guest.h" 5 #include "chrome/browser/guestview/webview/webview_guest.h"
6 6
7 #include "chrome/browser/extensions/api/web_request/web_request_api.h" 7 #include "chrome/browser/extensions/api/web_request/web_request_api.h"
8 #include "chrome/browser/extensions/extension_renderer_state.h" 8 #include "chrome/browser/extensions/extension_renderer_state.h"
9 #include "chrome/browser/extensions/script_executor.h" 9 #include "chrome/browser/extensions/script_executor.h"
10 #include "chrome/browser/favicon/favicon_tab_helper.h" 10 #include "chrome/browser/favicon/favicon_tab_helper.h"
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 NOTREACHED(); 64 NOTREACHED();
65 break; 65 break;
66 } 66 }
67 return std::string(); 67 return std::string();
68 } 68 }
69 69
70 void RemoveWebViewEventListenersOnIOThread( 70 void RemoveWebViewEventListenersOnIOThread(
71 void* profile, 71 void* profile,
72 const std::string& extension_id, 72 const std::string& extension_id,
73 int embedder_process_id, 73 int embedder_process_id,
74 int embedder_routing_id, 74 int view_instance_id) {
75 int guest_instance_id) {
76 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO)); 75 DCHECK(content::BrowserThread::CurrentlyOn(content::BrowserThread::IO));
77 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners( 76 ExtensionWebRequestEventRouter::GetInstance()->RemoveWebViewEventListeners(
78 profile, 77 profile,
79 extension_id, 78 extension_id,
80 embedder_process_id, 79 embedder_process_id,
81 embedder_routing_id, 80 view_instance_id);
82 guest_instance_id);
83 } 81 }
84 82
85 void AttachWebViewHelpers(WebContents* contents) { 83 void AttachWebViewHelpers(WebContents* contents) {
86 FaviconTabHelper::CreateForWebContents(contents); 84 FaviconTabHelper::CreateForWebContents(contents);
87 } 85 }
88 86
89 } // namespace 87 } // namespace
90 88
91 WebViewGuest::WebViewGuest(WebContents* guest_web_contents) 89 WebViewGuest::WebViewGuest(WebContents* guest_web_contents)
92 : GuestView(guest_web_contents), 90 : GuestView(guest_web_contents),
(...skipping 54 matching lines...) Expand 10 before | Expand all | Expand 10 after
147 args->SetString(webview::kSourceId, source_id); 145 args->SetString(webview::kSourceId, source_id);
148 DispatchEvent( 146 DispatchEvent(
149 new GuestView::Event(webview::kEventConsoleMessage, args.Pass())); 147 new GuestView::Event(webview::kEventConsoleMessage, args.Pass()));
150 } 148 }
151 149
152 void WebViewGuest::Close() { 150 void WebViewGuest::Close() {
153 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 151 scoped_ptr<DictionaryValue> args(new DictionaryValue());
154 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass())); 152 DispatchEvent(new GuestView::Event(webview::kEventClose, args.Pass()));
155 } 153 }
156 154
155 void WebViewGuest::EmbedderDestroyed() {
156 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
157 // reparenting of a <webview> within a single embedder. Right now, we keep
158 // around the browser state for the listener for the lifetime of the embedder.
159 // Ideally, the lifetime of the listeners should match the lifetime of the
160 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
161 // the call to RemoveWebViewEventListenersOnIOThread back to
162 // WebViewGuest::WebContentsDestroyed.
163 content::BrowserThread::PostTask(
164 content::BrowserThread::IO,
165 FROM_HERE,
166 base::Bind(
167 &RemoveWebViewEventListenersOnIOThread,
168 browser_context(), extension_id(),
169 embedder_render_process_id(),
170 view_instance_id()));
171 }
172
157 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) { 173 void WebViewGuest::GuestProcessGone(base::TerminationStatus status) {
158 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 174 scoped_ptr<DictionaryValue> args(new DictionaryValue());
159 args->SetInteger(webview::kProcessId, 175 args->SetInteger(webview::kProcessId,
160 web_contents()->GetRenderProcessHost()->GetID()); 176 web_contents()->GetRenderProcessHost()->GetID());
161 args->SetString(webview::kReason, TerminationStatusToString(status)); 177 args->SetString(webview::kReason, TerminationStatusToString(status));
162 DispatchEvent( 178 DispatchEvent(
163 new GuestView::Event(webview::kEventExit, args.Pass())); 179 new GuestView::Event(webview::kEventExit, args.Pass()));
164 } 180 }
165 181
166 bool WebViewGuest::HandleKeyboardEvent( 182 bool WebViewGuest::HandleKeyboardEvent(
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass())); 408 DispatchEvent(new GuestView::Event(webview::kEventLoadStart, args.Pass()));
393 } 409 }
394 410
395 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) { 411 void WebViewGuest::DidStopLoading(content::RenderViewHost* render_view_host) {
396 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 412 scoped_ptr<DictionaryValue> args(new DictionaryValue());
397 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass())); 413 DispatchEvent(new GuestView::Event(webview::kEventLoadStop, args.Pass()));
398 } 414 }
399 415
400 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) { 416 void WebViewGuest::WebContentsDestroyed(WebContents* web_contents) {
401 RemoveWebViewFromExtensionRendererState(web_contents); 417 RemoveWebViewFromExtensionRendererState(web_contents);
402 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
403 // reparenting of a <webview> within a single embedder. The lifetime of
404 // WebRequest event listeners should be equal to the lifetime of the embedder
405 // WebContents rather than the guest until http://crbug.com/156219 is
406 // resolved.
407 content::BrowserThread::PostTask(
408 content::BrowserThread::IO,
409 FROM_HERE,
410 base::Bind(
411 &RemoveWebViewEventListenersOnIOThread,
412 browser_context(), extension_id(),
413 embedder_render_process_id(),
414 embedder_routing_id(),
415 view_instance_id()));
416 } 418 }
417 419
418 void WebViewGuest::LoadHandlerCalled() { 420 void WebViewGuest::LoadHandlerCalled() {
419 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 421 scoped_ptr<DictionaryValue> args(new DictionaryValue());
420 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass())); 422 DispatchEvent(new GuestView::Event(webview::kEventContentLoad, args.Pass()));
421 } 423 }
422 424
423 void WebViewGuest::LoadRedirect(const GURL& old_url, 425 void WebViewGuest::LoadRedirect(const GURL& old_url,
424 const GURL& new_url, 426 const GURL& new_url,
425 bool is_top_level) { 427 bool is_top_level) {
426 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 428 scoped_ptr<DictionaryValue> args(new DictionaryValue());
427 args->SetBoolean(guestview::kIsTopLevel, is_top_level); 429 args->SetBoolean(guestview::kIsTopLevel, is_top_level);
428 args->SetString(webview::kNewURL, new_url.spec()); 430 args->SetString(webview::kNewURL, new_url.spec());
429 args->SetString(webview::kOldURL, old_url.spec()); 431 args->SetString(webview::kOldURL, old_url.spec());
430 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass())); 432 DispatchEvent(new GuestView::Event(webview::kEventLoadRedirect, args.Pass()));
431 } 433 }
432 434
433 void WebViewGuest::AddWebViewToExtensionRendererState() { 435 void WebViewGuest::AddWebViewToExtensionRendererState() {
434 ExtensionRendererState::WebViewInfo webview_info; 436 ExtensionRendererState::WebViewInfo webview_info;
435 webview_info.embedder_process_id = embedder_render_process_id(); 437 webview_info.embedder_process_id = embedder_render_process_id();
436 webview_info.embedder_routing_id = embedder_web_contents()->GetRoutingID();
437 webview_info.instance_id = view_instance_id(); 438 webview_info.instance_id = view_instance_id();
438 439
439 content::BrowserThread::PostTask( 440 content::BrowserThread::PostTask(
440 content::BrowserThread::IO, FROM_HERE, 441 content::BrowserThread::IO, FROM_HERE,
441 base::Bind( 442 base::Bind(
442 &ExtensionRendererState::AddWebView, 443 &ExtensionRendererState::AddWebView,
443 base::Unretained(ExtensionRendererState::GetInstance()), 444 base::Unretained(ExtensionRendererState::GetInstance()),
444 guest_web_contents()->GetRenderProcessHost()->GetID(), 445 guest_web_contents()->GetRenderProcessHost()->GetID(),
445 guest_web_contents()->GetRoutingID(), 446 guest_web_contents()->GetRoutingID(),
446 webview_info)); 447 webview_info));
(...skipping 13 matching lines...) Expand all
460 461
461 void WebViewGuest::SizeChanged(const gfx::Size& old_size, 462 void WebViewGuest::SizeChanged(const gfx::Size& old_size,
462 const gfx::Size& new_size) { 463 const gfx::Size& new_size) {
463 scoped_ptr<DictionaryValue> args(new DictionaryValue()); 464 scoped_ptr<DictionaryValue> args(new DictionaryValue());
464 args->SetInteger(webview::kOldHeight, old_size.height()); 465 args->SetInteger(webview::kOldHeight, old_size.height());
465 args->SetInteger(webview::kOldWidth, old_size.width()); 466 args->SetInteger(webview::kOldWidth, old_size.width());
466 args->SetInteger(webview::kNewHeight, new_size.height()); 467 args->SetInteger(webview::kNewHeight, new_size.height());
467 args->SetInteger(webview::kNewWidth, new_size.width()); 468 args->SetInteger(webview::kNewWidth, new_size.width());
468 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass())); 469 DispatchEvent(new GuestView::Event(webview::kEventSizeChanged, args.Pass()));
469 } 470 }
OLDNEW
« no previous file with comments | « chrome/browser/guestview/webview/webview_guest.h ('k') | chrome/chrome_renderer.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698