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

Side by Side Diff: chrome/browser/guest_view/web_view/web_view_guest.cc

Issue 306003002: Move guest lifetime management to chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed content_browsertests crash Created 6 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
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/guest_view/web_view/web_view_guest.h" 5 #include "chrome/browser/guest_view/web_view/web_view_guest.h"
6 6
7 #include "base/message_loop/message_loop.h" 7 #include "base/message_loop/message_loop.h"
8 #include "base/strings/stringprintf.h" 8 #include "base/strings/stringprintf.h"
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/browser/chrome_notification_types.h" 10 #include "chrome/browser/chrome_notification_types.h"
(...skipping 159 matching lines...) Expand 10 before | Expand all | Expand 10 after
170 } 170 }
171 171
172 } // namespace 172 } // namespace
173 173
174 WebViewGuest::WebViewGuest(int guest_instance_id, 174 WebViewGuest::WebViewGuest(int guest_instance_id,
175 WebContents* guest_web_contents, 175 WebContents* guest_web_contents,
176 const std::string& embedder_extension_id) 176 const std::string& embedder_extension_id)
177 : GuestView<WebViewGuest>(guest_instance_id, 177 : GuestView<WebViewGuest>(guest_instance_id,
178 guest_web_contents, 178 guest_web_contents,
179 embedder_extension_id), 179 embedder_extension_id),
180 WebContentsObserver(guest_web_contents),
181 script_executor_(new extensions::ScriptExecutor(guest_web_contents, 180 script_executor_(new extensions::ScriptExecutor(guest_web_contents,
182 &script_observers_)), 181 &script_observers_)),
183 pending_context_menu_request_id_(0), 182 pending_context_menu_request_id_(0),
184 next_permission_request_id_(0), 183 next_permission_request_id_(0),
185 is_overriding_user_agent_(false), 184 is_overriding_user_agent_(false),
186 pending_reload_on_attachment_(false), 185 pending_reload_on_attachment_(false),
187 main_frame_id_(0), 186 main_frame_id_(0),
188 chromevox_injected_(false), 187 chromevox_injected_(false),
189 find_helper_(this), 188 find_helper_(this),
190 javascript_dialog_helper_(this) { 189 javascript_dialog_helper_(this) {
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
327 SetUserAgentOverride(user_agent_override); 326 SetUserAgentOverride(user_agent_override);
328 } else { 327 } else {
329 SetUserAgentOverride(""); 328 SetUserAgentOverride("");
330 } 329 }
331 330
332 GuestViewBase::Attach(embedder_web_contents, args); 331 GuestViewBase::Attach(embedder_web_contents, args);
333 332
334 AddWebViewToExtensionRendererState(); 333 AddWebViewToExtensionRendererState();
335 } 334 }
336 335
337 bool WebViewGuest::HandleContextMenu( 336 void WebViewGuest::EmbedderDestroyed() {
338 const content::ContextMenuParams& params) { 337 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
339 ContextMenuDelegate* menu_delegate = 338 // reparenting of a <webview> within a single embedder. Right now, we keep
340 ContextMenuDelegate::FromWebContents(guest_web_contents()); 339 // around the browser state for the listener for the lifetime of the embedder.
341 DCHECK(menu_delegate); 340 // Ideally, the lifetime of the listeners should match the lifetime of the
342 341 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
343 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params); 342 // the call to RemoveWebViewEventListenersOnIOThread back to
344 343 // WebViewGuest::WebContentsDestroyed.
345 // Pass it to embedder. 344 content::BrowserThread::PostTask(
346 int request_id = ++pending_context_menu_request_id_; 345 content::BrowserThread::IO,
347 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 346 FROM_HERE,
348 scoped_ptr<base::ListValue> items = 347 base::Bind(
349 MenuModelToValue(pending_menu_->menu_model()); 348 &RemoveWebViewEventListenersOnIOThread,
350 args->Set(webview::kContextMenuItems, items.release()); 349 browser_context(), embedder_extension_id(),
351 args->SetInteger(webview::kRequestId, request_id); 350 embedder_render_process_id(),
352 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu, 351 view_instance_id()));
353 args.Pass()));
354 return true;
355 } 352 }
356 353
357 bool WebViewGuest::AddMessageToConsole(WebContents* source, 354 bool WebViewGuest::AddMessageToConsole(WebContents* source,
358 int32 level, 355 int32 level,
359 const base::string16& message, 356 const base::string16& message,
360 int32 line_no, 357 int32 line_no,
361 const base::string16& source_id) { 358 const base::string16& source_id) {
362 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); 359 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
363 // Log levels are from base/logging.h: LogSeverity. 360 // Log levels are from base/logging.h: LogSeverity.
364 args->SetInteger(webview::kLevel, level); 361 args->SetInteger(webview::kLevel, level);
(...skipping 29 matching lines...) Expand all
394 // lifetime of the new guest is no longer managed by the opener guest. 391 // lifetime of the new guest is no longer managed by the opener guest.
395 GetOpener()->pending_new_windows_.erase(this); 392 GetOpener()->pending_new_windows_.erase(this);
396 } 393 }
397 394
398 if (pending_reload_on_attachment_) { 395 if (pending_reload_on_attachment_) {
399 pending_reload_on_attachment_ = false; 396 pending_reload_on_attachment_ = false;
400 guest_web_contents()->GetController().Reload(false); 397 guest_web_contents()->GetController().Reload(false);
401 } 398 }
402 } 399 }
403 400
404 void WebViewGuest::EmbedderDestroyed() {
405 // TODO(fsamuel): WebRequest event listeners for <webview> should survive
406 // reparenting of a <webview> within a single embedder. Right now, we keep
407 // around the browser state for the listener for the lifetime of the embedder.
408 // Ideally, the lifetime of the listeners should match the lifetime of the
409 // <webview> DOM node. Once http://crbug.com/156219 is resolved we can move
410 // the call to RemoveWebViewEventListenersOnIOThread back to
411 // WebViewGuest::WebContentsDestroyed.
412 content::BrowserThread::PostTask(
413 content::BrowserThread::IO,
414 FROM_HERE,
415 base::Bind(
416 &RemoveWebViewEventListenersOnIOThread,
417 browser_context(), embedder_extension_id(),
418 embedder_render_process_id(),
419 view_instance_id()));
420 }
421
422 void WebViewGuest::FindReply(WebContents* source, 401 void WebViewGuest::FindReply(WebContents* source,
423 int request_id, 402 int request_id,
424 int number_of_matches, 403 int number_of_matches,
425 const gfx::Rect& selection_rect, 404 const gfx::Rect& selection_rect,
426 int active_match_ordinal, 405 int active_match_ordinal,
427 bool final_update) { 406 bool final_update) {
428 find_helper_.FindReply(request_id, number_of_matches, selection_rect, 407 find_helper_.FindReply(request_id, number_of_matches, selection_rect,
429 active_match_ordinal, final_update); 408 active_match_ordinal, final_update);
430 } 409 }
431 410
411 bool WebViewGuest::HandleContextMenu(
412 const content::ContextMenuParams& params) {
413 ContextMenuDelegate* menu_delegate =
414 ContextMenuDelegate::FromWebContents(guest_web_contents());
415 DCHECK(menu_delegate);
416
417 pending_menu_ = menu_delegate->BuildMenu(guest_web_contents(), params);
418
419 // Pass it to embedder.
420 int request_id = ++pending_context_menu_request_id_;
421 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue());
422 scoped_ptr<base::ListValue> items =
423 MenuModelToValue(pending_menu_->menu_model());
424 args->Set(webview::kContextMenuItems, items.release());
425 args->SetInteger(webview::kRequestId, request_id);
426 DispatchEvent(new GuestViewBase::Event(webview::kEventContextMenu,
427 args.Pass()));
428 return true;
429 }
430
432 void WebViewGuest::HandleKeyboardEvent( 431 void WebViewGuest::HandleKeyboardEvent(
433 WebContents* source, 432 WebContents* source,
434 const content::NativeWebKeyboardEvent& event) { 433 const content::NativeWebKeyboardEvent& event) {
435 if (!attached()) 434 if (!attached())
436 return; 435 return;
437 436
438 if (HandleKeyboardShortcuts(event)) 437 if (HandleKeyboardShortcuts(event))
439 return; 438 return;
440 439
441 // Send the unhandled keyboard events back to the embedder to reprocess them. 440 // Send the unhandled keyboard events back to the embedder to reprocess them.
(...skipping 434 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 } 875 }
877 876
878 void WebViewGuest::WebContentsDestroyed() { 877 void WebViewGuest::WebContentsDestroyed() {
879 // Clean up custom context menu items for this guest. 878 // Clean up custom context menu items for this guest.
880 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( 879 extensions::MenuManager* menu_manager = extensions::MenuManager::Get(
881 Profile::FromBrowserContext(browser_context())); 880 Profile::FromBrowserContext(browser_context()));
882 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( 881 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey(
883 embedder_extension_id(), view_instance_id())); 882 embedder_extension_id(), view_instance_id()));
884 883
885 RemoveWebViewFromExtensionRendererState(web_contents()); 884 RemoveWebViewFromExtensionRendererState(web_contents());
885 GuestViewBase::WebContentsDestroyed();
886 } 886 }
887 887
888 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { 888 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) {
889 content::NavigationController& controller = 889 content::NavigationController& controller =
890 guest_web_contents()->GetController(); 890 guest_web_contents()->GetController();
891 content::NavigationEntry* entry = controller.GetVisibleEntry(); 891 content::NavigationEntry* entry = controller.GetVisibleEntry();
892 if (!entry) 892 if (!entry)
893 return; 893 return;
894 entry->SetIsOverridingUserAgent(!user_agent.empty()); 894 entry->SetIsOverridingUserAgent(!user_agent.empty());
895 if (!attached()) { 895 if (!attached()) {
(...skipping 513 matching lines...) Expand 10 before | Expand all | Expand 10 after
1409 bool allow, 1409 bool allow,
1410 const std::string& user_input) { 1410 const std::string& user_input) {
1411 WebViewGuest* guest = 1411 WebViewGuest* guest =
1412 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); 1412 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id);
1413 if (!guest) 1413 if (!guest)
1414 return; 1414 return;
1415 1415
1416 if (!allow) 1416 if (!allow)
1417 guest->Destroy(); 1417 guest->Destroy();
1418 } 1418 }
OLDNEW
« no previous file with comments | « chrome/browser/guest_view/web_view/web_view_guest.h ('k') | content/browser/browser_plugin/browser_plugin_guest.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698