summaryrefslogtreecommitdiffstats
path: root/athena
diff options
context:
space:
mode:
authorflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-23 22:00:16 +0000
committerflackr@chromium.org <flackr@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-07-23 22:00:16 +0000
commitb00e23415d3a57469e76469a96a5a7860d7eb802 (patch)
tree14119677977f02734e2f0f2e8d2d7bfece9fb64a /athena
parente8696c3bcd7d1ff309e7fbe431f3139c68182b01 (diff)
downloadchromium_src-b00e23415d3a57469e76469a96a5a7860d7eb802.zip
chromium_src-b00e23415d3a57469e76469a96a5a7860d7eb802.tar.gz
chromium_src-b00e23415d3a57469e76469a96a5a7860d7eb802.tar.bz2
Handle WebContents created for new windows and create activities for these.
BUG=391473 TEST=Follow a link from Gmail or hold shift when clicking a link. A new activity following the link is created. Review URL: https://codereview.chromium.org/398603002 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@285049 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'athena')
-rw-r--r--athena/content/web_activity.cc92
-rw-r--r--athena/content/web_activity.h1
2 files changed, 75 insertions, 18 deletions
diff --git a/athena/content/web_activity.cc b/athena/content/web_activity.cc
index 69d44f0..15d3e56 100644
--- a/athena/content/web_activity.cc
+++ b/athena/content/web_activity.cc
@@ -4,10 +4,13 @@
#include "athena/content/web_activity.h"
+#include "athena/activity/public/activity_factory.h"
#include "athena/activity/public/activity_manager.h"
#include "athena/input/public/accelerator_manager.h"
#include "content/public/browser/native_web_keyboard_event.h"
+#include "content/public/browser/navigation_controller.h"
#include "content/public/browser/web_contents.h"
+#include "content/public/browser/web_contents_delegate.h"
#include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
#include "ui/views/controls/webview/webview.h"
#include "ui/views/focus/focus_manager.h"
@@ -124,32 +127,30 @@ class AthenaWebView : public views::WebView {
public:
AthenaWebView(content::BrowserContext* context)
: views::WebView(context), controller_(new WebActivityController(this)) {
- // We create the first web contents ourselves to allow us to replace it
- // later on.
- SetWebContents(content::WebContents::Create(
- content::WebContents::CreateParams(context)));
// TODO(skuhne): Add content observer to detect renderer crash and set
// content status to unloaded if that happens.
}
- virtual ~AthenaWebView() {
- // |WebView| does not own the content, so we need to destroy it here.
- content::WebContents* current_contents = GetWebContents();
- SetWebContents(NULL);
- delete current_contents;
+
+ AthenaWebView(content::WebContents* web_contents)
+ : views::WebView(web_contents->GetBrowserContext()),
+ controller_(new WebActivityController(this)) {
+ scoped_ptr<content::WebContents> old_contents(
+ SwapWebContents(scoped_ptr<content::WebContents>(web_contents)));
}
+ virtual ~AthenaWebView() {}
+
void InstallAccelerators() { controller_->InstallAccelerators(); }
void EvictContent() {
- content::WebContents* old_contents = GetWebContents();
+ scoped_ptr<content::WebContents> old_contents(SwapWebContents(
+ scoped_ptr<content::WebContents>(content::WebContents::Create(
+ content::WebContents::CreateParams(browser_context())))));
evicted_web_contents_.reset(
content::WebContents::Create(content::WebContents::CreateParams(
old_contents->GetBrowserContext())));
evicted_web_contents_->GetController().CopyStateFrom(
old_contents->GetController());
- SetWebContents(content::WebContents::Create(
- content::WebContents::CreateParams(old_contents->GetBrowserContext())));
- delete old_contents;
// As soon as the new contents becomes visible, it should reload.
// TODO(skuhne): This breaks script connections with other activities.
// Even though this is the same technique as used by the TabStripModel,
@@ -159,16 +160,60 @@ class AthenaWebView : public views::WebView {
void ReloadContent() {
CHECK(evicted_web_contents_.get());
- content::WebContents* null_contents = GetWebContents();
- SetWebContents(evicted_web_contents_.release());
- delete null_contents;
+ scoped_ptr<content::WebContents> replaced_contents(SwapWebContents(
+ evicted_web_contents_.Pass()));
}
// Check if the content got evicted.
const bool IsContentEvicted() { return !!evicted_web_contents_.get(); }
- private:
- // WebContentsDelegate:
+ // content::WebContentsDelegate:
+ virtual content::WebContents* OpenURLFromTab(
+ content::WebContents* source,
+ const content::OpenURLParams& params) OVERRIDE {
+ switch(params.disposition) {
+ case CURRENT_TAB: {
+ DCHECK(source == web_contents());
+ content::NavigationController::LoadURLParams load_url_params(
+ params.url);
+ load_url_params.referrer = params.referrer;
+ load_url_params.frame_tree_node_id = params.frame_tree_node_id;
+ load_url_params.transition_type = params.transition;
+ load_url_params.extra_headers = params.extra_headers;
+ load_url_params.should_replace_current_entry =
+ params.should_replace_current_entry;
+ load_url_params.is_renderer_initiated = params.is_renderer_initiated;
+ load_url_params.transferred_global_request_id =
+ params.transferred_global_request_id;
+ web_contents()->GetController().LoadURLWithParams(load_url_params);
+ return web_contents();
+ }
+ case NEW_FOREGROUND_TAB:
+ case NEW_BACKGROUND_TAB:
+ case NEW_POPUP:
+ case NEW_WINDOW: {
+ ActivityManager::Get()->AddActivity(
+ ActivityFactory::Get()->CreateWebActivity(browser_context(),
+ params.url));
+ break;
+ }
+ default:
+ break;
+ }
+ // NULL is returned if the URL wasn't opened immediately.
+ return NULL;
+ }
+
+ virtual void AddNewContents(content::WebContents* source,
+ content::WebContents* new_contents,
+ WindowOpenDisposition disposition,
+ const gfx::Rect& initial_pos,
+ bool user_gesture,
+ bool* was_blocked) OVERRIDE {
+ ActivityManager::Get()->AddActivity(
+ new WebActivity(new AthenaWebView(new_contents)));
+ }
+
virtual bool PreHandleKeyboardEvent(
content::WebContents* source,
const content::NativeWebKeyboardEvent& event,
@@ -183,6 +228,7 @@ class AthenaWebView : public views::WebView {
controller_->HandleKeyboardEvent(source, event);
}
+ private:
scoped_ptr<WebActivityController> controller_;
// If the activity got evicted, this is the web content which holds the known
@@ -200,6 +246,16 @@ WebActivity::WebActivity(content::BrowserContext* browser_context,
current_state_(ACTIVITY_UNLOADED) {
}
+WebActivity::WebActivity(AthenaWebView* web_view)
+ : browser_context_(web_view->browser_context()),
+ url_(web_view->GetWebContents()->GetURL()),
+ web_view_(web_view),
+ current_state_(ACTIVITY_UNLOADED) {
+ // Transition to state ACTIVITY_INVISIBLE to perform the same setup steps
+ // as on new activities (namely adding a WebContentsObserver).
+ SetCurrentState(ACTIVITY_INVISIBLE);
+}
+
WebActivity::~WebActivity() {
// It is not required to change the activity state to UNLOADED - unless we
// would add state observers.
diff --git a/athena/content/web_activity.h b/athena/content/web_activity.h
index 850f93a..45407a4 100644
--- a/athena/content/web_activity.h
+++ b/athena/content/web_activity.h
@@ -29,6 +29,7 @@ class WebActivity : public Activity,
public content::WebContentsObserver {
public:
WebActivity(content::BrowserContext* context, const GURL& gurl);
+ WebActivity(AthenaWebView* web_view);
virtual ~WebActivity();
protected: