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

Side by Side Diff: athena/extensions/chrome/athena_chrome_app_delegate.cc

Issue 563083003: V2 app support step3: Athena's NativeAppWindow (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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 "athena/extensions/chrome/athena_app_delegate.h" 5 #include "athena/extensions/chrome/athena_chrome_app_delegate.h"
6 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" 7 #include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
14 #include "chrome/browser/favicon/favicon_tab_helper.h" 8 #include "chrome/browser/favicon/favicon_tab_helper.h"
15 #include "chrome/browser/file_select_helper.h" 9 #include "chrome/browser/file_select_helper.h"
16 #include "chrome/browser/media/media_capture_devices_dispatcher.h" 10 #include "chrome/browser/media/media_capture_devices_dispatcher.h"
17 #include "chrome/browser/platform_util.h" 11 #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" 12 #include "chrome/browser/ui/browser.h"
21 #include "chrome/browser/ui/browser_dialogs.h" 13 #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" 14 #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" 15 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/web_contents.h" 16 #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 17
36 #if defined(ENABLE_PRINTING) 18 #if defined(ENABLE_PRINTING)
37 #if defined(ENABLE_FULL_PRINTING) 19 #if defined(ENABLE_FULL_PRINTING)
38 #include "chrome/browser/printing/print_preview_message_handler.h" 20 #include "chrome/browser/printing/print_preview_message_handler.h"
39 #include "chrome/browser/printing/print_view_manager.h" 21 #include "chrome/browser/printing/print_view_manager.h"
40 #else 22 #else
41 #include "chrome/browser/printing/print_view_manager_basic.h" 23 #include "chrome/browser/printing/print_view_manager_basic.h"
42 #endif // defined(ENABLE_FULL_PRINTING) 24 #endif // defined(ENABLE_FULL_PRINTING)
43 #endif // defined(ENABLE_PRINTING) 25 #endif // defined(ENABLE_PRINTING)
44 26
45 namespace athena { 27 namespace athena {
46 namespace {
47 28
48 content::WebContents* OpenURLInActivity( 29 AthenaChromeAppDelegate::AthenaChromeAppDelegate() {
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 } 30 }
58 31
59 } // namespace 32 AthenaChromeAppDelegate::~AthenaChromeAppDelegate() {
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 } 33 }
86 34
87 AthenaAppDelegate::~AthenaAppDelegate() { 35 void AthenaChromeAppDelegate::InitWebContents(
88 if (!terminating_callback_.is_null()) 36 content::WebContents* web_contents) {
89 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_);
90 }
91
92 void AthenaAppDelegate::InitWebContents(content::WebContents* web_contents) {
93 FaviconTabHelper::CreateForWebContents(web_contents); 37 FaviconTabHelper::CreateForWebContents(web_contents);
94 38
95 #if defined(ENABLE_PRINTING) 39 #if defined(ENABLE_PRINTING)
96 #if defined(ENABLE_FULL_PRINTING) 40 #if defined(ENABLE_FULL_PRINTING)
97 printing::PrintViewManager::CreateForWebContents(web_contents); 41 printing::PrintViewManager::CreateForWebContents(web_contents);
98 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents); 42 printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
99 #else 43 #else
100 printing::PrintViewManagerBasic::CreateForWebContents(web_contents); 44 printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
101 #endif // defined(ENABLE_FULL_PRINTING) 45 #endif // defined(ENABLE_FULL_PRINTING)
102 #endif // defined(ENABLE_PRINTING) 46 #endif // defined(ENABLE_PRINTING)
103 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents( 47 extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
104 web_contents); 48 web_contents);
105 } 49 }
106 50
107 void AthenaAppDelegate::ResizeWebContents(content::WebContents* web_contents, 51 content::ColorChooser* AthenaChromeAppDelegate::ShowColorChooser(
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, 52 content::WebContents* web_contents,
130 SkColor initial_color) { 53 SkColor initial_color) {
131 return chrome::ShowColorChooser(web_contents, initial_color); 54 return chrome::ShowColorChooser(web_contents, initial_color);
132 } 55 }
133 56
134 void AthenaAppDelegate::RunFileChooser( 57 void AthenaChromeAppDelegate::RunFileChooser(
135 content::WebContents* tab, 58 content::WebContents* tab,
136 const content::FileChooserParams& params) { 59 const content::FileChooserParams& params) {
137 FileSelectHelper::RunFileChooser(tab, params); 60 FileSelectHelper::RunFileChooser(tab, params);
138 } 61 }
139 62
140 void AthenaAppDelegate::RequestMediaAccessPermission( 63 void AthenaChromeAppDelegate::RequestMediaAccessPermission(
141 content::WebContents* web_contents, 64 content::WebContents* web_contents,
142 const content::MediaStreamRequest& request, 65 const content::MediaStreamRequest& request,
143 const content::MediaResponseCallback& callback, 66 const content::MediaResponseCallback& callback,
144 const extensions::Extension* extension) { 67 const extensions::Extension* extension) {
145 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest( 68 MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
146 web_contents, request, callback, extension); 69 web_contents, request, callback, extension);
147 } 70 }
148 71
149 int AthenaAppDelegate::PreferredIconSize() { 72 void AthenaChromeAppDelegate::SetWebContentsBlocked(
150 // TODO(oshima): Find out what to use.
151 return extension_misc::EXTENSION_ICON_SMALL;
152 }
153
154 gfx::ImageSkia AthenaAppDelegate::GetAppDefaultIcon() {
155 return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
156 IDR_APP_DEFAULT_ICON);
157 }
158
159 void AthenaAppDelegate::SetWebContentsBlocked(
160 content::WebContents* web_contents, 73 content::WebContents* web_contents,
161 bool blocked) { 74 bool blocked) {
162 // RenderViewHost may be NULL during shutdown. 75 // RenderViewHost may be NULL during shutdown.
163 content::RenderViewHost* host = web_contents->GetRenderViewHost(); 76 content::RenderViewHost* host = web_contents->GetRenderViewHost();
164 if (host) { 77 if (host) {
165 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(host->GetRoutingID(), 78 host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(host->GetRoutingID(),
166 blocked)); 79 blocked));
167 } 80 }
168 } 81 }
169 82
170 bool AthenaAppDelegate::IsWebContentsVisible(
171 content::WebContents* web_contents) {
172 return platform_util::IsVisible(web_contents->GetNativeView());
173 }
174
175 void AthenaAppDelegate::SetTerminatingCallback(const base::Closure& callback) {
176 if (!terminating_callback_.is_null())
177 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_);
178 terminating_callback_ = callback;
179 if (!terminating_callback_.is_null())
180 AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_);
181 }
182
183 } // namespace athena 83 } // namespace athena
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698