| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "apps/custom_launcher_page_contents.h" | |
| 6 | |
| 7 #include <string> | |
| 8 #include <utility> | |
| 9 | |
| 10 #include "chrome/browser/chrome_notification_types.h" | |
| 11 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | |
| 12 #include "content/public/browser/render_view_host.h" | |
| 13 #include "content/public/browser/site_instance.h" | |
| 14 #include "content/public/browser/web_contents.h" | |
| 15 #include "content/public/common/renderer_preferences.h" | |
| 16 #include "extensions/browser/app_window/app_delegate.h" | |
| 17 #include "extensions/browser/app_window/app_web_contents_helper.h" | |
| 18 #include "extensions/browser/view_type_utils.h" | |
| 19 #include "extensions/common/extension_messages.h" | |
| 20 | |
| 21 namespace apps { | |
| 22 | |
| 23 CustomLauncherPageContents::CustomLauncherPageContents( | |
| 24 std::unique_ptr<extensions::AppDelegate> app_delegate, | |
| 25 const std::string& extension_id) | |
| 26 : app_delegate_(std::move(app_delegate)), extension_id_(extension_id) {} | |
| 27 | |
| 28 CustomLauncherPageContents::~CustomLauncherPageContents() { | |
| 29 } | |
| 30 | |
| 31 void CustomLauncherPageContents::Initialize(content::BrowserContext* context, | |
| 32 const GURL& url) { | |
| 33 web_contents_.reset( | |
| 34 content::WebContents::Create(content::WebContents::CreateParams( | |
| 35 context, content::SiteInstance::CreateForURL(context, url)))); | |
| 36 | |
| 37 web_contents_->GetMutableRendererPrefs() | |
| 38 ->browser_handles_all_top_level_requests = true; | |
| 39 web_contents_->GetRenderViewHost()->SyncRendererPrefs(); | |
| 40 | |
| 41 helper_.reset(new extensions::AppWebContentsHelper( | |
| 42 context, extension_id_, web_contents_.get(), app_delegate_.get())); | |
| 43 web_contents_->SetDelegate(this); | |
| 44 | |
| 45 extensions::SetViewType(web_contents(), extensions::VIEW_TYPE_LAUNCHER_PAGE); | |
| 46 | |
| 47 // This observer will activate the extension when it is navigated to, which | |
| 48 // allows Dispatcher to give it the proper context and makes it behave like an | |
| 49 // extension. | |
| 50 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
| 51 web_contents()); | |
| 52 | |
| 53 web_contents_->GetController().LoadURL(url, | |
| 54 content::Referrer(), | |
| 55 ui::PAGE_TRANSITION_AUTO_TOPLEVEL, | |
| 56 std::string()); | |
| 57 } | |
| 58 | |
| 59 content::WebContents* CustomLauncherPageContents::OpenURLFromTab( | |
| 60 content::WebContents* source, | |
| 61 const content::OpenURLParams& params) { | |
| 62 DCHECK_EQ(web_contents_.get(), source); | |
| 63 return helper_->OpenURLFromTab(params); | |
| 64 } | |
| 65 | |
| 66 void CustomLauncherPageContents::AddNewContents( | |
| 67 content::WebContents* source, | |
| 68 content::WebContents* new_contents, | |
| 69 WindowOpenDisposition disposition, | |
| 70 const gfx::Rect& initial_rect, | |
| 71 bool user_gesture, | |
| 72 bool* was_blocked) { | |
| 73 app_delegate_->AddNewContents(new_contents->GetBrowserContext(), | |
| 74 new_contents, | |
| 75 disposition, | |
| 76 initial_rect, | |
| 77 user_gesture, | |
| 78 was_blocked); | |
| 79 } | |
| 80 | |
| 81 bool CustomLauncherPageContents::IsPopupOrPanel( | |
| 82 const content::WebContents* source) const { | |
| 83 return true; | |
| 84 } | |
| 85 | |
| 86 bool CustomLauncherPageContents::ShouldSuppressDialogs( | |
| 87 content::WebContents* source) { | |
| 88 return true; | |
| 89 } | |
| 90 | |
| 91 bool CustomLauncherPageContents::PreHandleGestureEvent( | |
| 92 content::WebContents* source, | |
| 93 const blink::WebGestureEvent& event) { | |
| 94 return extensions::AppWebContentsHelper::ShouldSuppressGestureEvent(event); | |
| 95 } | |
| 96 | |
| 97 content::ColorChooser* CustomLauncherPageContents::OpenColorChooser( | |
| 98 content::WebContents* web_contents, | |
| 99 SkColor initial_color, | |
| 100 const std::vector<content::ColorSuggestion>& suggestionss) { | |
| 101 return app_delegate_->ShowColorChooser(web_contents, initial_color); | |
| 102 } | |
| 103 | |
| 104 void CustomLauncherPageContents::RunFileChooser( | |
| 105 content::RenderFrameHost* render_frame_host, | |
| 106 const content::FileChooserParams& params) { | |
| 107 app_delegate_->RunFileChooser(render_frame_host, params); | |
| 108 } | |
| 109 | |
| 110 void CustomLauncherPageContents::RequestToLockMouse( | |
| 111 content::WebContents* web_contents, | |
| 112 bool user_gesture, | |
| 113 bool last_unlocked_by_target) { | |
| 114 DCHECK_EQ(web_contents_.get(), web_contents); | |
| 115 helper_->RequestToLockMouse(); | |
| 116 } | |
| 117 | |
| 118 void CustomLauncherPageContents::RequestMediaAccessPermission( | |
| 119 content::WebContents* web_contents, | |
| 120 const content::MediaStreamRequest& request, | |
| 121 const content::MediaResponseCallback& callback) { | |
| 122 DCHECK_EQ(web_contents_.get(), web_contents); | |
| 123 helper_->RequestMediaAccessPermission(request, callback); | |
| 124 } | |
| 125 | |
| 126 bool CustomLauncherPageContents::CheckMediaAccessPermission( | |
| 127 content::WebContents* web_contents, | |
| 128 const GURL& security_origin, | |
| 129 content::MediaStreamType type) { | |
| 130 DCHECK_EQ(web_contents_.get(), web_contents); | |
| 131 return helper_->CheckMediaAccessPermission(security_origin, type); | |
| 132 } | |
| 133 | |
| 134 } // namespace apps | |
| OLD | NEW |