| 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/renderer_context_menu/render_view_context_menu.h" | 5 #include "chrome/browser/renderer_context_menu/render_view_context_menu.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 #include <memory> | 8 #include <memory> |
| 9 #include <string> | 9 #include <string> |
| 10 #include <utility> | 10 #include <utility> |
| 11 #include <vector> | 11 #include <vector> |
| 12 | 12 |
| 13 #include "base/bind.h" | 13 #include "base/bind.h" |
| 14 #include "base/command_line.h" | 14 #include "base/command_line.h" |
| 15 #include "base/macros.h" | 15 #include "base/macros.h" |
| 16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/memory/ref_counted.h" | 17 #include "base/memory/ref_counted.h" |
| 18 #include "base/run_loop.h" | 18 #include "base/run_loop.h" |
| 19 #include "base/strings/string16.h" | 19 #include "base/strings/string16.h" |
| 20 #include "base/strings/stringprintf.h" | 20 #include "base/strings/stringprintf.h" |
| 21 #include "base/strings/utf_string_conversions.h" | 21 #include "base/strings/utf_string_conversions.h" |
| 22 #include "base/threading/thread_restrictions.h" | 22 #include "base/threading/thread_restrictions.h" |
| 23 #include "build/build_config.h" | 23 #include "build/build_config.h" |
| 24 #include "chrome/app/chrome_command_ids.h" | 24 #include "chrome/app/chrome_command_ids.h" |
| 25 #include "chrome/browser/browser_process.h" | 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chrome_notification_types.h" | 26 #include "chrome/browser/chrome_notification_types.h" |
| 27 #include "chrome/browser/pdf/pdf_extension_test_util.h" | |
| 28 #include "chrome/browser/profiles/profile_attributes_entry.h" | 27 #include "chrome/browser/profiles/profile_attributes_entry.h" |
| 29 #include "chrome/browser/profiles/profile_attributes_storage.h" | 28 #include "chrome/browser/profiles/profile_attributes_storage.h" |
| 30 #include "chrome/browser/profiles/profile_window.h" | 29 #include "chrome/browser/profiles/profile_window.h" |
| 31 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" | 30 #include "chrome/browser/renderer_context_menu/render_view_context_menu_browsert
est_util.h" |
| 32 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" | 31 #include "chrome/browser/renderer_context_menu/render_view_context_menu_test_uti
l.h" |
| 33 #include "chrome/browser/search_engines/template_url_service_factory.h" | 32 #include "chrome/browser/search_engines/template_url_service_factory.h" |
| 34 #include "chrome/browser/ui/browser.h" | 33 #include "chrome/browser/ui/browser.h" |
| 35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 34 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 36 #include "chrome/common/render_messages.h" | 35 #include "chrome/common/render_messages.h" |
| 37 #include "chrome/common/thumbnail_capturer.mojom.h" | 36 #include "chrome/common/thumbnail_capturer.mojom.h" |
| 38 #include "chrome/grit/generated_resources.h" | |
| 39 #include "chrome/test/base/in_process_browser_test.h" | 37 #include "chrome/test/base/in_process_browser_test.h" |
| 40 #include "chrome/test/base/search_test_utils.h" | 38 #include "chrome/test/base/search_test_utils.h" |
| 41 #include "chrome/test/base/ui_test_utils.h" | 39 #include "chrome/test/base/ui_test_utils.h" |
| 42 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" | 40 #include "components/data_reduction_proxy/core/common/data_reduction_proxy_switc
hes.h" |
| 43 #include "components/guest_view/browser/guest_view_manager_delegate.h" | |
| 44 #include "components/guest_view/browser/test_guest_view_manager.h" | |
| 45 #include "components/search_engines/template_url_data.h" | 41 #include "components/search_engines/template_url_data.h" |
| 46 #include "components/search_engines/template_url_service.h" | 42 #include "components/search_engines/template_url_service.h" |
| 47 #include "content/public/browser/browser_message_filter.h" | 43 #include "content/public/browser/browser_message_filter.h" |
| 48 #include "content/public/browser/browser_plugin_guest_manager.h" | |
| 49 #include "content/public/browser/browser_thread.h" | 44 #include "content/public/browser/browser_thread.h" |
| 50 #include "content/public/browser/navigation_controller.h" | 45 #include "content/public/browser/navigation_controller.h" |
| 51 #include "content/public/browser/navigation_entry.h" | 46 #include "content/public/browser/navigation_entry.h" |
| 52 #include "content/public/browser/notification_service.h" | 47 #include "content/public/browser/notification_service.h" |
| 53 #include "content/public/browser/render_frame_host.h" | 48 #include "content/public/browser/render_frame_host.h" |
| 54 #include "content/public/browser/render_process_host.h" | 49 #include "content/public/browser/render_process_host.h" |
| 55 #include "content/public/browser/render_view_host.h" | 50 #include "content/public/browser/render_view_host.h" |
| 56 #include "content/public/browser/render_widget_host.h" | 51 #include "content/public/browser/render_widget_host.h" |
| 57 #include "content/public/browser/web_contents.h" | 52 #include "content/public/browser/web_contents.h" |
| 58 #include "content/public/test/browser_test_utils.h" | 53 #include "content/public/test/browser_test_utils.h" |
| 59 #include "content/public/test/test_utils.h" | 54 #include "content/public/test/test_utils.h" |
| 60 #include "extensions/browser/api/extensions_api_client.h" | |
| 61 #include "extensions/browser/guest_view/mime_handler_view/mime_handler_view_gues
t.h" | |
| 62 #include "extensions/browser/guest_view/mime_handler_view/test_mime_handler_view
_guest.h" | |
| 63 #include "net/base/load_flags.h" | 55 #include "net/base/load_flags.h" |
| 64 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
| 65 #include "net/url_request/url_request.h" | 57 #include "net/url_request/url_request.h" |
| 66 #include "net/url_request/url_request_filter.h" | 58 #include "net/url_request/url_request_filter.h" |
| 67 #include "net/url_request/url_request_interceptor.h" | 59 #include "net/url_request/url_request_interceptor.h" |
| 68 #include "services/service_manager/public/cpp/interface_provider.h" | 60 #include "services/service_manager/public/cpp/interface_provider.h" |
| 69 #include "third_party/WebKit/public/platform/WebInputEvent.h" | 61 #include "third_party/WebKit/public/platform/WebInputEvent.h" |
| 70 #include "third_party/WebKit/public/web/WebContextMenuData.h" | 62 #include "third_party/WebKit/public/web/WebContextMenuData.h" |
| 71 #include "ui/base/models/menu_model.h" | 63 #include "ui/base/models/menu_model.h" |
| 72 | 64 |
| 73 using content::WebContents; | 65 using content::WebContents; |
| 74 using extensions::MimeHandlerViewGuest; | |
| 75 using extensions::TestMimeHandlerViewGuest; | |
| 76 | 66 |
| 77 namespace { | 67 namespace { |
| 78 | 68 |
| 79 class ContextMenuBrowserTest : public InProcessBrowserTest { | 69 class ContextMenuBrowserTest : public InProcessBrowserTest { |
| 80 public: | 70 public: |
| 81 ContextMenuBrowserTest() {} | 71 ContextMenuBrowserTest() {} |
| 82 | 72 |
| 83 protected: | 73 protected: |
| 84 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuMediaTypeNone( | 74 std::unique_ptr<TestRenderViewContextMenu> CreateContextMenuMediaTypeNone( |
| 85 const GURL& unfiltered_url, | 75 const GURL& unfiltered_url, |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 Profile* CreateSecondaryProfile(int profile_num) { | 117 Profile* CreateSecondaryProfile(int profile_num) { |
| 128 base::ThreadRestrictions::ScopedAllowIO allow_io; | 118 base::ThreadRestrictions::ScopedAllowIO allow_io; |
| 129 ProfileManager* profile_manager = g_browser_process->profile_manager(); | 119 ProfileManager* profile_manager = g_browser_process->profile_manager(); |
| 130 base::FilePath profile_path = profile_manager->user_data_dir(); | 120 base::FilePath profile_path = profile_manager->user_data_dir(); |
| 131 profile_path = profile_path.AppendASCII( | 121 profile_path = profile_path.AppendASCII( |
| 132 base::StringPrintf("New Profile %d", profile_num)); | 122 base::StringPrintf("New Profile %d", profile_num)); |
| 133 return profile_manager->GetProfile(profile_path); | 123 return profile_manager->GetProfile(profile_path); |
| 134 } | 124 } |
| 135 }; | 125 }; |
| 136 | 126 |
| 137 class PdfPluginContextMenuBrowserTest : public InProcessBrowserTest { | |
| 138 public: | |
| 139 PdfPluginContextMenuBrowserTest() {} | |
| 140 | |
| 141 void SetUpOnMainThread() override { | |
| 142 guest_view::GuestViewManager::set_factory_for_testing(&factory_); | |
| 143 test_guest_view_manager_ = static_cast<guest_view::TestGuestViewManager*>( | |
| 144 guest_view::GuestViewManager::CreateWithDelegate( | |
| 145 browser()->profile(), | |
| 146 extensions::ExtensionsAPIClient::Get() | |
| 147 ->CreateGuestViewManagerDelegate(browser()->profile()))); | |
| 148 } | |
| 149 | |
| 150 protected: | |
| 151 guest_view::TestGuestViewManager* test_guest_view_manager() const { | |
| 152 return test_guest_view_manager_; | |
| 153 } | |
| 154 | |
| 155 // Helper function for testing context menu of a pdf plugin inside a web page. | |
| 156 void TestContextMenuOfPdfInsideWebPage( | |
| 157 const base::FilePath::CharType* file_name) { | |
| 158 // Load a page with pdf file inside. | |
| 159 GURL page_url = ui_test_utils::GetTestUrl( | |
| 160 base::FilePath(FILE_PATH_LITERAL("pdf")), base::FilePath(file_name)); | |
| 161 ui_test_utils::NavigateToURL(browser(), page_url); | |
| 162 | |
| 163 WebContents* web_contents = | |
| 164 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 165 // Prepare to load a pdf plugin inside. | |
| 166 test_guest_view_manager_->RegisterTestGuestViewType<MimeHandlerViewGuest>( | |
| 167 base::Bind(&TestMimeHandlerViewGuest::Create)); | |
| 168 ASSERT_TRUE( | |
| 169 content::ExecuteScript(web_contents, | |
| 170 "var l = document.getElementById('link1');" | |
| 171 "l.click();")); | |
| 172 | |
| 173 // Wait for the guest contents of the PDF plugin is created. | |
| 174 WebContents* guest_contents = | |
| 175 test_guest_view_manager_->WaitForSingleGuestCreated(); | |
| 176 TestMimeHandlerViewGuest* guest = static_cast<TestMimeHandlerViewGuest*>( | |
| 177 extensions::MimeHandlerViewGuest::FromWebContents(guest_contents)); | |
| 178 ASSERT_TRUE(guest); | |
| 179 // Wait for the guest is attached to the embedder. | |
| 180 guest->WaitForGuestAttached(); | |
| 181 ASSERT_NE(web_contents, guest_contents); | |
| 182 // Get the pdf plugin's main frame. | |
| 183 content::RenderFrameHost* frame = guest_contents->GetMainFrame(); | |
| 184 ASSERT_TRUE(frame); | |
| 185 | |
| 186 content::ContextMenuParams params; | |
| 187 params.page_url = page_url; | |
| 188 params.frame_url = frame->GetLastCommittedURL(); | |
| 189 params.frame_page_state = | |
| 190 content::PageState::CreateFromURL(params.frame_url); | |
| 191 params.media_type = blink::WebContextMenuData::kMediaTypePlugin; | |
| 192 TestRenderViewContextMenu menu(frame, params); | |
| 193 menu.Init(); | |
| 194 | |
| 195 // The full page related items such as 'reload' should not be displayed. | |
| 196 ASSERT_FALSE(menu.IsItemPresent(IDC_RELOAD)); | |
| 197 } | |
| 198 | |
| 199 private: | |
| 200 guest_view::TestGuestViewManagerFactory factory_; | |
| 201 guest_view::TestGuestViewManager* test_guest_view_manager_; | |
| 202 | |
| 203 DISALLOW_COPY_AND_ASSIGN(PdfPluginContextMenuBrowserTest); | |
| 204 }; | |
| 205 | |
| 206 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, | 127 IN_PROC_BROWSER_TEST_F(ContextMenuBrowserTest, |
| 207 OpenEntryPresentForNormalURLs) { | 128 OpenEntryPresentForNormalURLs) { |
| 208 std::unique_ptr<TestRenderViewContextMenu> menu = | 129 std::unique_ptr<TestRenderViewContextMenu> menu = |
| 209 CreateContextMenuMediaTypeNone(GURL("http://www.google.com/"), | 130 CreateContextMenuMediaTypeNone(GURL("http://www.google.com/"), |
| 210 GURL("http://www.google.com/")); | 131 GURL("http://www.google.com/")); |
| 211 | 132 |
| 212 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); | 133 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWTAB)); |
| 213 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); | 134 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKNEWWINDOW)); |
| 214 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); | 135 ASSERT_TRUE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_COPYLINKLOCATION)); |
| 215 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); | 136 ASSERT_FALSE(menu->IsItemPresent(IDC_CONTENT_CONTEXT_OPENLINKINPROFILE)); |
| (...skipping 527 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 743 thumbnail_capturer->RequestThumbnailForContextNode( | 664 thumbnail_capturer->RequestThumbnailForContextNode( |
| 744 0, gfx::Size(2048, 2048), | 665 0, gfx::Size(2048, 2048), |
| 745 base::Bind(callback, &response_received, run_loop.QuitClosure())); | 666 base::Bind(callback, &response_received, run_loop.QuitClosure())); |
| 746 run_loop.Run(); | 667 run_loop.Run(); |
| 747 | 668 |
| 748 // The browser should receive a response from the renderer, because the | 669 // The browser should receive a response from the renderer, because the |
| 749 // renderer should not crash. | 670 // renderer should not crash. |
| 750 ASSERT_TRUE(response_received); | 671 ASSERT_TRUE(response_received); |
| 751 } | 672 } |
| 752 | 673 |
| 753 IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest, | |
| 754 FullPagePdfHasPageItems) { | |
| 755 // Load a pdf page. | |
| 756 GURL page_url = | |
| 757 ui_test_utils::GetTestUrl(base::FilePath(FILE_PATH_LITERAL("pdf")), | |
| 758 base::FilePath(FILE_PATH_LITERAL("test.pdf"))); | |
| 759 ui_test_utils::NavigateToURL(browser(), page_url); | |
| 760 | |
| 761 WebContents* web_contents = | |
| 762 browser()->tab_strip_model()->GetActiveWebContents(); | |
| 763 // Wait for the PDF plugin is loaded. | |
| 764 pdf_extension_test_util::EnsurePDFHasLoaded(web_contents); | |
| 765 content::BrowserPluginGuestManager* guest_manager = | |
| 766 web_contents->GetBrowserContext()->GetGuestManager(); | |
| 767 WebContents* guest_contents = guest_manager->GetFullPageGuest(web_contents); | |
| 768 ASSERT_TRUE(guest_contents); | |
| 769 // Get the pdf plugin's main frame. | |
| 770 content::RenderFrameHost* frame = guest_contents->GetMainFrame(); | |
| 771 ASSERT_TRUE(frame); | |
| 772 ASSERT_NE(frame, web_contents->GetMainFrame()); | |
| 773 | |
| 774 content::ContextMenuParams params; | |
| 775 params.page_url = page_url; | |
| 776 params.frame_url = frame->GetLastCommittedURL(); | |
| 777 params.frame_page_state = content::PageState::CreateFromURL(params.frame_url); | |
| 778 params.media_type = blink::WebContextMenuData::kMediaTypePlugin; | |
| 779 TestRenderViewContextMenu menu(frame, params); | |
| 780 menu.Init(); | |
| 781 | |
| 782 // The full page related items such as 'reload' should be there. | |
| 783 ASSERT_TRUE(menu.IsItemPresent(IDC_RELOAD)); | |
| 784 } | |
| 785 | |
| 786 IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest, | |
| 787 EmbeddedPdfHasNoPageItems) { | |
| 788 TestContextMenuOfPdfInsideWebPage(FILE_PATH_LITERAL("test-embed-pdf.html")); | |
| 789 } | |
| 790 | |
| 791 IN_PROC_BROWSER_TEST_F(PdfPluginContextMenuBrowserTest, | |
| 792 IframedPdfHasNoPageItems) { | |
| 793 TestContextMenuOfPdfInsideWebPage(FILE_PATH_LITERAL("test-iframe-pdf.html")); | |
| 794 } | |
| 795 | |
| 796 class LoadImageRequestInterceptor : public net::URLRequestInterceptor { | 674 class LoadImageRequestInterceptor : public net::URLRequestInterceptor { |
| 797 public: | 675 public: |
| 798 LoadImageRequestInterceptor() : num_requests_(0), | 676 LoadImageRequestInterceptor() : num_requests_(0), |
| 799 requests_to_wait_for_(-1), | 677 requests_to_wait_for_(-1), |
| 800 weak_factory_(this) { | 678 weak_factory_(this) { |
| 801 } | 679 } |
| 802 | 680 |
| 803 ~LoadImageRequestInterceptor() override {} | 681 ~LoadImageRequestInterceptor() override {} |
| 804 | 682 |
| 805 // net::URLRequestInterceptor implementation | 683 // net::URLRequestInterceptor implementation |
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 913 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { | 791 IN_PROC_BROWSER_TEST_F(LoadImageBrowserTest, LoadImage) { |
| 914 static const char kValidImage[] = "/load_image/image.png"; | 792 static const char kValidImage[] = "/load_image/image.png"; |
| 915 SetupAndLoadImagePage(kValidImage); | 793 SetupAndLoadImagePage(kValidImage); |
| 916 AddLoadImageInterceptor(kValidImage); | 794 AddLoadImageInterceptor(kValidImage); |
| 917 AttemptLoadImage(); | 795 AttemptLoadImage(); |
| 918 interceptor_->WaitForRequests(1); | 796 interceptor_->WaitForRequests(1); |
| 919 EXPECT_EQ(1, interceptor_->num_requests()); | 797 EXPECT_EQ(1, interceptor_->num_requests()); |
| 920 } | 798 } |
| 921 | 799 |
| 922 } // namespace | 800 } // namespace |
| OLD | NEW |