OLD | NEW |
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 341 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
352 content::BrowserThread::PostTask( | 352 content::BrowserThread::PostTask( |
353 content::BrowserThread::IO, | 353 content::BrowserThread::IO, |
354 FROM_HERE, | 354 FROM_HERE, |
355 base::Bind( | 355 base::Bind( |
356 &RemoveWebViewEventListenersOnIOThread, | 356 &RemoveWebViewEventListenersOnIOThread, |
357 browser_context(), embedder_extension_id(), | 357 browser_context(), embedder_extension_id(), |
358 embedder_render_process_id(), | 358 embedder_render_process_id(), |
359 view_instance_id())); | 359 view_instance_id())); |
360 } | 360 } |
361 | 361 |
| 362 void WebViewGuest::GuestDestroyed() { |
| 363 // Clean up custom context menu items for this guest. |
| 364 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( |
| 365 Profile::FromBrowserContext(browser_context())); |
| 366 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( |
| 367 embedder_extension_id(), view_instance_id())); |
| 368 |
| 369 RemoveWebViewFromExtensionRendererState(web_contents()); |
| 370 } |
| 371 |
362 bool WebViewGuest::IsDragAndDropEnabled() const { | 372 bool WebViewGuest::IsDragAndDropEnabled() const { |
363 return true; | 373 return true; |
364 } | 374 } |
365 | 375 |
| 376 void WebViewGuest::WillDestroy() { |
| 377 if (!attached() && GetOpener()) |
| 378 GetOpener()->pending_new_windows_.erase(this); |
| 379 DestroyUnattachedWindows(); |
| 380 } |
| 381 |
366 bool WebViewGuest::AddMessageToConsole(WebContents* source, | 382 bool WebViewGuest::AddMessageToConsole(WebContents* source, |
367 int32 level, | 383 int32 level, |
368 const base::string16& message, | 384 const base::string16& message, |
369 int32 line_no, | 385 int32 line_no, |
370 const base::string16& source_id) { | 386 const base::string16& source_id) { |
371 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 387 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
372 // Log levels are from base/logging.h: LogSeverity. | 388 // Log levels are from base/logging.h: LogSeverity. |
373 args->SetInteger(webview::kLevel, level); | 389 args->SetInteger(webview::kLevel, level); |
374 args->SetString(webview::kMessage, message); | 390 args->SetString(webview::kMessage, message); |
375 args->SetInteger(webview::kLine, line_no); | 391 args->SetInteger(webview::kLine, line_no); |
(...skipping 482 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
858 // Cancel all find sessions in progress. | 874 // Cancel all find sessions in progress. |
859 find_helper_.CancelAllFindSessions(); | 875 find_helper_.CancelAllFindSessions(); |
860 | 876 |
861 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 877 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
862 args->SetInteger(webview::kProcessId, | 878 args->SetInteger(webview::kProcessId, |
863 guest_web_contents()->GetRenderProcessHost()->GetID()); | 879 guest_web_contents()->GetRenderProcessHost()->GetID()); |
864 args->SetString(webview::kReason, TerminationStatusToString(status)); | 880 args->SetString(webview::kReason, TerminationStatusToString(status)); |
865 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); | 881 DispatchEvent(new GuestViewBase::Event(webview::kEventExit, args.Pass())); |
866 } | 882 } |
867 | 883 |
868 void WebViewGuest::WebContentsDestroyed() { | |
869 // Clean up custom context menu items for this guest. | |
870 extensions::MenuManager* menu_manager = extensions::MenuManager::Get( | |
871 Profile::FromBrowserContext(browser_context())); | |
872 menu_manager->RemoveAllContextItems(extensions::MenuItem::ExtensionKey( | |
873 embedder_extension_id(), view_instance_id())); | |
874 | |
875 RemoveWebViewFromExtensionRendererState(web_contents()); | |
876 GuestViewBase::WebContentsDestroyed(); | |
877 } | |
878 | |
879 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { | 884 void WebViewGuest::UserAgentOverrideSet(const std::string& user_agent) { |
880 content::NavigationController& controller = | 885 content::NavigationController& controller = |
881 guest_web_contents()->GetController(); | 886 guest_web_contents()->GetController(); |
882 content::NavigationEntry* entry = controller.GetVisibleEntry(); | 887 content::NavigationEntry* entry = controller.GetVisibleEntry(); |
883 if (!entry) | 888 if (!entry) |
884 return; | 889 return; |
885 entry->SetIsOverridingUserAgent(!user_agent.empty()); | 890 entry->SetIsOverridingUserAgent(!user_agent.empty()); |
886 if (!attached()) { | 891 if (!attached()) { |
887 // We cannot reload now because all resource loads are suspended until | 892 // We cannot reload now because all resource loads are suspended until |
888 // attachment. | 893 // attachment. |
(...skipping 373 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1262 | 1267 |
1263 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); | 1268 scoped_ptr<base::DictionaryValue> args(new base::DictionaryValue()); |
1264 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); | 1269 args->SetDouble(webview::kOldZoomFactor, current_zoom_factor_); |
1265 args->SetDouble(webview::kNewZoomFactor, zoom_factor); | 1270 args->SetDouble(webview::kNewZoomFactor, zoom_factor); |
1266 DispatchEvent( | 1271 DispatchEvent( |
1267 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); | 1272 new GuestViewBase::Event(webview::kEventZoomChange, args.Pass())); |
1268 | 1273 |
1269 current_zoom_factor_ = zoom_factor; | 1274 current_zoom_factor_ = zoom_factor; |
1270 } | 1275 } |
1271 | 1276 |
1272 void WebViewGuest::Destroy() { | |
1273 if (!attached() && GetOpener()) | |
1274 GetOpener()->pending_new_windows_.erase(this); | |
1275 DestroyUnattachedWindows(); | |
1276 GuestViewBase::Destroy(); | |
1277 } | |
1278 | |
1279 void WebViewGuest::AddNewContents(content::WebContents* source, | 1277 void WebViewGuest::AddNewContents(content::WebContents* source, |
1280 content::WebContents* new_contents, | 1278 content::WebContents* new_contents, |
1281 WindowOpenDisposition disposition, | 1279 WindowOpenDisposition disposition, |
1282 const gfx::Rect& initial_pos, | 1280 const gfx::Rect& initial_pos, |
1283 bool user_gesture, | 1281 bool user_gesture, |
1284 bool* was_blocked) { | 1282 bool* was_blocked) { |
1285 if (was_blocked) | 1283 if (was_blocked) |
1286 *was_blocked = false; | 1284 *was_blocked = false; |
1287 RequestNewWindowPermission(disposition, | 1285 RequestNewWindowPermission(disposition, |
1288 initial_pos, | 1286 initial_pos, |
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1415 bool allow, | 1413 bool allow, |
1416 const std::string& user_input) { | 1414 const std::string& user_input) { |
1417 WebViewGuest* guest = | 1415 WebViewGuest* guest = |
1418 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); | 1416 WebViewGuest::From(embedder_render_process_id(), new_window_instance_id); |
1419 if (!guest) | 1417 if (!guest) |
1420 return; | 1418 return; |
1421 | 1419 |
1422 if (!allow) | 1420 if (!allow) |
1423 guest->Destroy(); | 1421 guest->Destroy(); |
1424 } | 1422 } |
OLD | NEW |