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.
5 #include "athena/extensions/athena_app_delegate_base.h"
7 #include "athena/activity/public/activity.h"
8 #include "athena/activity/public/activity_factory.h"
9 #include "athena/env/public/athena_env.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/browser/web_contents_delegate.h"
12 #include "extensions/common/constants.h"
13 #include "extensions/grit/extensions_browser_resources.h"
14 #include "ui/aura/window.h"
15 #include "ui/base/resource/resource_bundle.h"
16 #include "ui/gfx/geometry/rect.h"
21 content::WebContents
* OpenURLInActivity(content::BrowserContext
* context
,
22 const content::OpenURLParams
& params
) {
23 // Force all links to open in a new activity.
24 Activity
* activity
= ActivityFactory::Get()->CreateWebActivity(
25 context
, base::string16(), params
.url
);
26 Activity::Show(activity
);
27 // TODO(oshima): Get the web cotnents from activity.
33 // This is a extra step to open a new Activity when a link is simply clicked
34 // on an app activity (which usually replaces the content).
35 class AthenaAppDelegateBase::NewActivityContentsDelegate
36 : public content::WebContentsDelegate
{
38 NewActivityContentsDelegate() {}
39 ~NewActivityContentsDelegate() override
{}
41 // content::WebContentsDelegate:
42 content::WebContents
* OpenURLFromTab(
43 content::WebContents
* source
,
44 const content::OpenURLParams
& params
) override
{
47 return OpenURLInActivity(source
->GetBrowserContext(), params
);
51 DISALLOW_COPY_AND_ASSIGN(NewActivityContentsDelegate
);
54 AthenaAppDelegateBase::AthenaAppDelegateBase()
55 : new_window_contents_delegate_(new NewActivityContentsDelegate
) {
58 AthenaAppDelegateBase::~AthenaAppDelegateBase() {
59 if (!terminating_callback_
.is_null())
60 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_
);
63 void AthenaAppDelegateBase::ResizeWebContents(
64 content::WebContents
* web_contents
,
65 const gfx::Size
& size
) {
66 aura::Window
* window
= web_contents
->GetNativeView();
67 window
->SetBounds(gfx::Rect(window
->bounds().origin(), size
));
70 content::WebContents
* AthenaAppDelegateBase::OpenURLFromTab(
71 content::BrowserContext
* context
,
72 content::WebContents
* source
,
73 const content::OpenURLParams
& params
) {
74 return OpenURLInActivity(context
, params
);
77 void AthenaAppDelegateBase::AddNewContents(content::BrowserContext
* context
,
78 content::WebContents
* new_contents
,
79 WindowOpenDisposition disposition
,
80 const gfx::Rect
& initial_pos
,
83 new_contents
->SetDelegate(new_window_contents_delegate_
.get());
86 int AthenaAppDelegateBase::PreferredIconSize() {
87 // TODO(oshima): Find out what to use.
88 return extension_misc::EXTENSION_ICON_SMALL
;
91 bool AthenaAppDelegateBase::IsWebContentsVisible(
92 content::WebContents
* web_contents
) {
93 return web_contents
->GetNativeView()->IsVisible();
96 void AthenaAppDelegateBase::SetTerminatingCallback(
97 const base::Closure
& callback
) {
98 if (!terminating_callback_
.is_null())
99 AthenaEnv::Get()->RemoveTerminatingCallback(terminating_callback_
);
100 terminating_callback_
= callback
;
101 if (!terminating_callback_
.is_null())
102 AthenaEnv::Get()->AddTerminatingCallback(terminating_callback_
);
105 } // namespace athena