| 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 "athena/extensions/chrome/athena_app_delegate.h" | |
| 6 | |
| 7 #include "athena/activity/public/activity_factory.h" | |
| 8 #include "athena/activity/public/activity_manager.h" | |
| 9 #include "athena/env/public/athena_env.h" | |
| 10 #include "base/memory/scoped_ptr.h" | |
| 11 #include "base/strings/stringprintf.h" | |
| 12 #include "chrome/browser/chrome_notification_types.h" | |
| 13 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h" | |
| 14 #include "chrome/browser/favicon/favicon_tab_helper.h" | |
| 15 #include "chrome/browser/file_select_helper.h" | |
| 16 #include "chrome/browser/media/media_capture_devices_dispatcher.h" | |
| 17 #include "chrome/browser/platform_util.h" | |
| 18 #include "chrome/browser/profiles/profile.h" | |
| 19 #include "chrome/browser/shell_integration.h" | |
| 20 #include "chrome/browser/ui/browser.h" | |
| 21 #include "chrome/browser/ui/browser_dialogs.h" | |
| 22 #include "chrome/browser/ui/browser_tabstrip.h" | |
| 23 #include "chrome/browser/ui/browser_window.h" | |
| 24 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.h" | |
| 25 #include "chrome/browser/ui/web_contents_sizer.h" | |
| 26 #include "chrome/common/extensions/chrome_extension_messages.h" | |
| 27 #include "content/public/browser/browser_context.h" | |
| 28 #include "content/public/browser/notification_service.h" | |
| 29 #include "content/public/browser/render_view_host.h" | |
| 30 #include "content/public/browser/web_contents.h" | |
| 31 #include "content/public/browser/web_contents_delegate.h" | |
| 32 #include "extensions/common/constants.h" | |
| 33 #include "extensions/grit/extensions_browser_resources.h" | |
| 34 #include "ui/base/resource/resource_bundle.h" | |
| 35 | |
| 36 #if defined(ENABLE_PRINTING) | |
| 37 #if defined(ENABLE_FULL_PRINTING) | |
| 38 #include "chrome/browser/printing/print_preview_message_handler.h" | |
| 39 #include "chrome/browser/printing/print_view_manager.h" | |
| 40 #else | |
| 41 #include "chrome/browser/printing/print_view_manager_basic.h" | |
| 42 #endif // defined(ENABLE_FULL_PRINTING) | |
| 43 #endif // defined(ENABLE_PRINTING) | |
| 44 | |
| 45 namespace athena { | |
| 46 namespace { | |
| 47 | |
| 48 content::WebContents* OpenURLInActivity( | |
| 49 content::BrowserContext* context, | |
| 50 const content::OpenURLParams& params) { | |
| 51 // Force all links to open in a new activity. | |
| 52 Activity* activity = ActivityFactory::Get()->CreateWebActivity( | |
| 53 context, base::string16(), params.url); | |
| 54 ActivityManager::Get()->AddActivity(activity); | |
| 55 // TODO(oshima): Get the web cotnents from activity. | |
| 56 return NULL; | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 61 // This is a extra step to open a new Activity when a link is simply clicked | |
| 62 // on an app activity (which usually replaces the content). | |
| 63 class AthenaAppDelegate::NewWindowContentsDelegate | |
| 64 : public content::WebContentsDelegate { | |
| 65 public: | |
| 66 NewWindowContentsDelegate() {} | |
| 67 virtual ~NewWindowContentsDelegate() {} | |
| 68 | |
| 69 // content::WebContentsDelegate: | |
| 70 virtual content::WebContents* OpenURLFromTab( | |
| 71 content::WebContents* source, | |
| 72 const content::OpenURLParams& params) OVERRIDE { | |
| 73 if (!source) | |
| 74 return NULL; | |
| 75 | |
| 76 return OpenURLInActivity(source->GetBrowserContext(), params); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 DISALLOW_COPY_AND_ASSIGN(NewWindowContentsDelegate); | |
| 81 }; | |
| 82 | |
| 83 AthenaAppDelegate::AthenaAppDelegate() | |
| 84 : new_window_contents_delegate_(new NewWindowContentsDelegate()) { | |
| 85 } | |
| 86 | |
| 87 AthenaAppDelegate::~AthenaAppDelegate() { | |
| 88 if (!terminating_callback_.is_null()) | |
| 89 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); | |
| 90 } | |
| 91 | |
| 92 void AthenaAppDelegate::InitWebContents(content::WebContents* web_contents) { | |
| 93 FaviconTabHelper::CreateForWebContents(web_contents); | |
| 94 | |
| 95 #if defined(ENABLE_PRINTING) | |
| 96 #if defined(ENABLE_FULL_PRINTING) | |
| 97 printing::PrintViewManager::CreateForWebContents(web_contents); | |
| 98 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); | |
| 99 #else | |
| 100 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); | |
| 101 #endif // defined(ENABLE_FULL_PRINTING) | |
| 102 #endif // defined(ENABLE_PRINTING) | |
| 103 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( | |
| 104 web_contents); | |
| 105 } | |
| 106 | |
| 107 void AthenaAppDelegate::ResizeWebContents(content::WebContents* web_contents, | |
| 108 const gfx::Size& size) { | |
| 109 ::ResizeWebContents(web_contents, size); | |
| 110 } | |
| 111 | |
| 112 content::WebContents* AthenaAppDelegate::OpenURLFromTab( | |
| 113 content::BrowserContext* context, | |
| 114 content::WebContents* source, | |
| 115 const content::OpenURLParams& params) { | |
| 116 return OpenURLInActivity(context, params); | |
| 117 } | |
| 118 | |
| 119 void AthenaAppDelegate::AddNewContents(content::BrowserContext* context, | |
| 120 content::WebContents* new_contents, | |
| 121 WindowOpenDisposition disposition, | |
| 122 const gfx::Rect& initial_pos, | |
| 123 bool user_gesture, | |
| 124 bool* was_blocked) { | |
| 125 new_contents->SetDelegate(new_window_contents_delegate_.get()); | |
| 126 } | |
| 127 | |
| 128 content::ColorChooser* AthenaAppDelegate::ShowColorChooser( | |
| 129 content::WebContents* web_contents, | |
| 130 SkColor initial_color) { | |
| 131 return chrome::ShowColorChooser(web_contents, initial_color); | |
| 132 } | |
| 133 | |
| 134 void AthenaAppDelegate::RunFileChooser( | |
| 135 content::WebContents* tab, | |
| 136 const content::FileChooserParams& params) { | |
| 137 FileSelectHelper::RunFileChooser(tab, params); | |
| 138 } | |
| 139 | |
| 140 void AthenaAppDelegate::RequestMediaAccessPermission( | |
| 141 content::WebContents* web_contents, | |
| 142 const content::MediaStreamRequest& request, | |
| 143 const content::MediaResponseCallback& callback, | |
| 144 const extensions::Extension* extension) { | |
| 145 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( | |
| 146 web_contents, request, callback, extension); | |
| 147 } | |
| 148 | |
| 149 bool AthenaAppDelegate::CheckMediaAccessPermission( | |
| 150 content::WebContents* web_contents, | |
| 151 const GURL& security_origin, | |
| 152 content::MediaStreamType type, | |
| 153 const extensions::Extension* extension) { | |
| 154 return MediaCaptureDevicesDispatcher::GetInstance() | |
| 155 ->CheckMediaAccessPermission( | |
| 156 web_contents, security_origin, type, extension); | |
| 157 } | |
| 158 | |
| 159 int AthenaAppDelegate::PreferredIconSize() { | |
| 160 // TODO(oshima): Find out what to use. | |
| 161 return extension_misc::EXTENSION_ICON_SMALL; | |
| 162 } | |
| 163 | |
| 164 gfx::ImageSkia AthenaAppDelegate::GetAppDefaultIcon() { | |
| 165 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed( | |
| 166 IDR_APP_DEFAULT_ICON); | |
| 167 } | |
| 168 | |
| 169 void AthenaAppDelegate::SetWebContentsBlocked( | |
| 170 content::WebContents* web_contents, | |
| 171 bool blocked) { | |
| 172 // RenderViewHost may be NULL during shutdown. | |
| 173 content::RenderViewHost* host = web_contents->GetRenderViewHost(); | |
| 174 if (host) { | |
| 175 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(host->GetRoutingID(), | |
| 176 blocked)); | |
| 177 } | |
| 178 } | |
| 179 | |
| 180 bool AthenaAppDelegate::IsWebContentsVisible( | |
| 181 content::WebContents* web_contents) { | |
| 182 return platform_util::IsVisible(web_contents->GetNativeView()); | |
| 183 } | |
| 184 | |
| 185 void AthenaAppDelegate::SetTerminatingCallback(const base::Closure& callback) { | |
| 186 if (!terminating_callback_.is_null()) | |
| 187 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_); | |
| 188 terminating_callback_ = callback; | |
| 189 if (!terminating_callback_.is_null()) | |
| 190 AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_); | |
| 191 } | |
| 192 | |
| 193 } // namespace athena | |
| OLD | NEW |