summaryrefslogtreecommitdiffstats
path: root/athena/extensions
diff options
context:
space:
mode:
authoroshima <oshima@chromium.org>2014-09-09 23:30:42 -0700
committerCommit bot <commit-bot@chromium.org>2014-09-10 06:34:47 +0000
commit480242d63b091995b58c1e21940249d91af9544f (patch)
treed3d998db3ca8526aa1c4b1e7c162b729bf0243a6 /athena/extensions
parente17158e079e4e51686d001ac288d9066c1ae310a (diff)
downloadchromium_src-480242d63b091995b58c1e21940249d91af9544f.zip
chromium_src-480242d63b091995b58c1e21940249d91af9544f.tar.gz
chromium_src-480242d63b091995b58c1e21940249d91af9544f.tar.bz2
Supprot V2 app: step1
* Add AthenaAppDelegate * Add factory functions to create various dialogs * Add terminating callback to AthenaEnv BUG=411415 TEST=AthenaEnvTest.TerminatingCallback TBR=sky@chromium.org, jochen@chromium.org, reed@chromium.org Review URL: https://codereview.chromium.org/544953003 Cr-Commit-Position: refs/heads/master@{#294123}
Diffstat (limited to 'athena/extensions')
-rw-r--r--athena/extensions/chrome/DEPS3
-rw-r--r--athena/extensions/chrome/athena_app_delegate.cc183
-rw-r--r--athena/extensions/chrome/athena_app_delegate.h64
-rw-r--r--athena/extensions/chrome/athena_apps_client.cc4
4 files changed, 252 insertions, 2 deletions
diff --git a/athena/extensions/chrome/DEPS b/athena/extensions/chrome/DEPS
index 33a05ca1..e9caa68 100644
--- a/athena/extensions/chrome/DEPS
+++ b/athena/extensions/chrome/DEPS
@@ -1,5 +1,8 @@
include_rules = [
+ "+athena/env/public",
"+chrome/browser",
"+chrome/common/extensions",
+ "+content/public/browser",
"+net/base",
+ "+ui/base",
]
diff --git a/athena/extensions/chrome/athena_app_delegate.cc b/athena/extensions/chrome/athena_app_delegate.cc
new file mode 100644
index 0000000..64d8d0a
--- /dev/null
+++ b/athena/extensions/chrome/athena_app_delegate.cc
@@ -0,0 +1,183 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "athena/extensions/chrome/athena_app_delegate.h"
+
+#include "athena/activity/public/activity_factory.h"
+#include "athena/activity/public/activity_manager.h"
+#include "athena/env/public/athena_env.h"
+#include "base/memory/scoped_ptr.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/extensions/chrome_extension_web_contents_observer.h"
+#include "chrome/browser/favicon/favicon_tab_helper.h"
+#include "chrome/browser/file_select_helper.h"
+#include "chrome/browser/media/media_capture_devices_dispatcher.h"
+#include "chrome/browser/platform_util.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/shell_integration.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/browser_dialogs.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/browser_window.h"
+#include "chrome/browser/ui/scoped_tabbed_browser_displayer.h"
+#include "chrome/browser/ui/web_contents_sizer.h"
+#include "chrome/common/extensions/chrome_extension_messages.h"
+#include "content/public/browser/browser_context.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/browser/render_view_host.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
+#include "extensions/common/constants.h"
+#include "extensions/grit/extensions_browser_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+
+#if defined(ENABLE_PRINTING)
+#if defined(ENABLE_FULL_PRINTING)
+#include "chrome/browser/printing/print_preview_message_handler.h"
+#include "chrome/browser/printing/print_view_manager.h"
+#else
+#include "chrome/browser/printing/print_view_manager_basic.h"
+#endif // defined(ENABLE_FULL_PRINTING)
+#endif // defined(ENABLE_PRINTING)
+
+namespace athena {
+namespace {
+
+content::WebContents* OpenURLInActivity(
+ content::BrowserContext* context,
+ const content::OpenURLParams& params) {
+ // Force all links to open in a new activity.
+ Activity* activity = ActivityFactory::Get()->CreateWebActivity(
+ context, base::string16(), params.url);
+ ActivityManager::Get()->AddActivity(activity);
+ // TODO(oshima): Get the web cotnents from activity.
+ return NULL;
+}
+
+} // namespace
+
+// This is a extra step to open a new Activity when a link is simply clicked
+// on an app activity (which usually replaces the content).
+class AthenaAppDelegate::NewWindowContentsDelegate
+ : public content::WebContentsDelegate {
+ public:
+ NewWindowContentsDelegate() {}
+ virtual ~NewWindowContentsDelegate() {}
+
+ // content::WebContentsDelegate:
+ virtual content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE {
+ if (!source)
+ return NULL;
+
+ return OpenURLInActivity(source->GetBrowserContext(), params);
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(NewWindowContentsDelegate);
+};
+
+AthenaAppDelegate::AthenaAppDelegate()
+ : new_window_contents_delegate_(new NewWindowContentsDelegate()) {
+}
+
+AthenaAppDelegate::~AthenaAppDelegate() {
+ if (!terminating_callback_.is_null())
+ AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_);
+}
+
+void AthenaAppDelegate::InitWebContents(content::WebContents* web_contents) {
+ FaviconTabHelper::CreateForWebContents(web_contents);
+
+#if defined(ENABLE_PRINTING)
+#if defined(ENABLE_FULL_PRINTING)
+ printing::PrintViewManager::CreateForWebContents(web_contents);
+ printing::PrintPreviewMessageHandler::CreateForWebContents(web_contents);
+#else
+ printing::PrintViewManagerBasic::CreateForWebContents(web_contents);
+#endif // defined(ENABLE_FULL_PRINTING)
+#endif // defined(ENABLE_PRINTING)
+ extensions::ChromeExtensionWebContentsObserver::CreateForWebContents(
+ web_contents);
+}
+
+void AthenaAppDelegate::ResizeWebContents(content::WebContents* web_contents,
+ const gfx::Size& size) {
+ ::ResizeWebContents(web_contents, size);
+}
+
+content::WebContents* AthenaAppDelegate::OpenURLFromTab(
+ content::BrowserContext* context,
+ content::WebContents* source,
+ const content::OpenURLParams& params) {
+ return OpenURLInActivity(context, params);
+}
+
+void AthenaAppDelegate::AddNewContents(content::BrowserContext* context,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ bool* was_blocked) {
+ new_contents->SetDelegate(new_window_contents_delegate_.get());
+}
+
+content::ColorChooser* AthenaAppDelegate::ShowColorChooser(
+ content::WebContents* web_contents,
+ SkColor initial_color) {
+ return chrome::ShowColorChooser(web_contents, initial_color);
+}
+
+void AthenaAppDelegate::RunFileChooser(
+ content::WebContents* tab,
+ const content::FileChooserParams& params) {
+ FileSelectHelper::RunFileChooser(tab, params);
+}
+
+void AthenaAppDelegate::RequestMediaAccessPermission(
+ content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback,
+ const extensions::Extension* extension) {
+ MediaCaptureDevicesDispatcher::GetInstance()->ProcessMediaAccessRequest(
+ web_contents, request, callback, extension);
+}
+
+int AthenaAppDelegate::PreferredIconSize() {
+ // TODO(oshima): Find out what to use.
+ return extension_misc::EXTENSION_ICON_SMALL;
+}
+
+gfx::ImageSkia AthenaAppDelegate::GetAppDefaultIcon() {
+ return *ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
+ IDR_APP_DEFAULT_ICON);
+}
+
+void AthenaAppDelegate::SetWebContentsBlocked(
+ content::WebContents* web_contents,
+ bool blocked) {
+ // RenderViewHost may be NULL during shutdown.
+ content::RenderViewHost* host = web_contents->GetRenderViewHost();
+ if (host) {
+ host->Send(new ChromeViewMsg_SetVisuallyDeemphasized(host->GetRoutingID(),
+ blocked));
+ }
+}
+
+bool AthenaAppDelegate::IsWebContentsVisible(
+ content::WebContents* web_contents) {
+ return platform_util::IsVisible(web_contents->GetNativeView());
+}
+
+void AthenaAppDelegate::SetTerminatingCallback(const base::Closure& callback) {
+ if (!terminating_callback_.is_null())
+ AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_);
+ terminating_callback_ = callback;
+ if (!terminating_callback_.is_null())
+ AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_);
+}
+
+} // namespace athena
diff --git a/athena/extensions/chrome/athena_app_delegate.h b/athena/extensions/chrome/athena_app_delegate.h
new file mode 100644
index 0000000..0c41a7b
--- /dev/null
+++ b/athena/extensions/chrome/athena_app_delegate.h
@@ -0,0 +1,64 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#ifndef ATHENA_EXTENSIONS_CHROME_ATHENA_APP_DELEGATE_H_
+#define ATHENA_EXTENSIONS_CHROME_ATHENA_APP_DELEGATE_H_
+
+#include "base/callback.h"
+#include "base/memory/scoped_ptr.h"
+#include "extensions/browser/app_window/app_delegate.h"
+#include "ui/base/window_open_disposition.h"
+
+namespace athena {
+
+class AthenaAppDelegate : public extensions::AppDelegate {
+ public:
+ AthenaAppDelegate();
+ virtual ~AthenaAppDelegate();
+
+ private:
+ class NewWindowContentsDelegate;
+
+ // extensions::AppDelegate:
+ virtual void InitWebContents(content::WebContents* web_contents) OVERRIDE;
+ virtual void ResizeWebContents(content::WebContents* web_contents,
+ const gfx::Size& size) OVERRIDE;
+ virtual content::WebContents* OpenURLFromTab(
+ content::BrowserContext* context,
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE;
+ virtual void AddNewContents(content::BrowserContext* context,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ bool* was_blocked) OVERRIDE;
+ virtual content::ColorChooser* ShowColorChooser(
+ content::WebContents* web_contents,
+ SkColor initial_color) OVERRIDE;
+ virtual void RunFileChooser(
+ content::WebContents* tab,
+ const content::FileChooserParams& params) OVERRIDE;
+ virtual void RequestMediaAccessPermission(
+ content::WebContents* web_contents,
+ const content::MediaStreamRequest& request,
+ const content::MediaResponseCallback& callback,
+ const extensions::Extension* extension) OVERRIDE;
+ virtual int PreferredIconSize() OVERRIDE;
+ virtual gfx::ImageSkia GetAppDefaultIcon() OVERRIDE;
+ virtual void SetWebContentsBlocked(content::WebContents* web_contents,
+ bool blocked) OVERRIDE;
+ virtual bool IsWebContentsVisible(
+ content::WebContents* web_contents) OVERRIDE;
+ virtual void SetTerminatingCallback(const base::Closure& callback) OVERRIDE;
+
+ scoped_ptr<NewWindowContentsDelegate> new_window_contents_delegate_;
+ base::Closure terminating_callback_;
+
+ DISALLOW_COPY_AND_ASSIGN(AthenaAppDelegate);
+};
+
+} // namespace athena
+
+#endif // ATHENA_EXTENSIONS_CHROME_ATHENA_APP_DELEGATE_H_
diff --git a/athena/extensions/chrome/athena_apps_client.cc b/athena/extensions/chrome/athena_apps_client.cc
index 5339ff4..37a0531 100644
--- a/athena/extensions/chrome/athena_apps_client.cc
+++ b/athena/extensions/chrome/athena_apps_client.cc
@@ -6,11 +6,11 @@
#include "athena/activity/public/activity_factory.h"
#include "athena/activity/public/activity_manager.h"
+#include "athena/extensions/chrome/athena_app_delegate.h"
#include "base/memory/singleton.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/devtools/devtools_window.h"
#include "chrome/browser/profiles/profile_manager.h"
-#include "chrome/browser/ui/apps/chrome_app_delegate.h"
#include "chrome/browser/ui/views/apps/chrome_native_app_window_views.h"
#include "chrome/common/extensions/features/feature_channel.h"
#include "extensions/browser/app_window/app_window.h"
@@ -35,7 +35,7 @@ AthenaAppsClient::GetLoadedBrowserContexts() {
extensions::AppWindow* AthenaAppsClient::CreateAppWindow(
content::BrowserContext* context,
const extensions::Extension* extension) {
- return new extensions::AppWindow(context, new ChromeAppDelegate, extension);
+ return new extensions::AppWindow(context, new AthenaAppDelegate, extension);
}
extensions::NativeAppWindow* AthenaAppsClient::CreateNativeAppWindow(