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

Side by Side Diff: athena/content/web_activity.cc

Issue 398603002: athena: Handle WebContents created for new windows and create activities for these. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 6 years, 5 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 | Annotate | Revision Log
« no previous file with comments | « athena/content/web_activity.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/content/web_activity.h" 5 #include "athena/content/web_activity.h"
6 6
7 #include "athena/activity/public/activity_factory.h"
7 #include "athena/activity/public/activity_manager.h" 8 #include "athena/activity/public/activity_manager.h"
8 #include "athena/input/public/accelerator_manager.h" 9 #include "athena/input/public/accelerator_manager.h"
9 #include "content/public/browser/native_web_keyboard_event.h" 10 #include "content/public/browser/native_web_keyboard_event.h"
11 #include "content/public/browser/navigation_controller.h"
10 #include "content/public/browser/web_contents.h" 12 #include "content/public/browser/web_contents.h"
13 #include "content/public/browser/web_contents_delegate.h"
11 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h" 14 #include "ui/views/controls/webview/unhandled_keyboard_event_handler.h"
12 #include "ui/views/controls/webview/webview.h" 15 #include "ui/views/controls/webview/webview.h"
13 #include "ui/views/focus/focus_manager.h" 16 #include "ui/views/focus/focus_manager.h"
14 17
15 namespace athena { 18 namespace athena {
16 namespace { 19 namespace {
17 20
18 class WebActivityController : public AcceleratorHandler { 21 class WebActivityController : public AcceleratorHandler {
19 public: 22 public:
20 enum Command { 23 enum Command {
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } // namespace 122 } // namespace
120 123
121 // A web view for athena's web activity. Note that AthenaWebView will create its 124 // A web view for athena's web activity. Note that AthenaWebView will create its
122 // own content so that it can eject and reload it. 125 // own content so that it can eject and reload it.
123 class AthenaWebView : public views::WebView { 126 class AthenaWebView : public views::WebView {
124 public: 127 public:
125 AthenaWebView(content::BrowserContext* context) 128 AthenaWebView(content::BrowserContext* context)
126 : views::WebView(context), controller_(new WebActivityController(this)) { 129 : views::WebView(context), controller_(new WebActivityController(this)) {
127 // We create the first web contents ourselves to allow us to replace it 130 // We create the first web contents ourselves to allow us to replace it
128 // later on. 131 // later on.
129 SetWebContents(content::WebContents::Create( 132 content::WebContents* web_contents(content::WebContents::Create(
130 content::WebContents::CreateParams(context))); 133 content::WebContents::CreateParams(context)));
134 SetWebContents(web_contents);
135 web_contents->SetDelegate(this);
flackr 2014/07/15 21:41:05 FYI: The change in https://codereview.chromium.org
oshima 2014/07/16 16:51:08 Thanks for the fix. It was actually https://codere
flackr 2014/07/18 18:15:08 Oops, pasted the wrong link.
131 // TODO(skuhne): Add content observer to detect renderer crash and set 136 // TODO(skuhne): Add content observer to detect renderer crash and set
132 // content status to unloaded if that happens. 137 // content status to unloaded if that happens.
133 } 138 }
139
140 AthenaWebView(content::WebContents* web_contents)
141 : views::WebView(web_contents->GetBrowserContext()),
142 controller_(new WebActivityController(this)) {
143 SetWebContents(web_contents);
144 web_contents->SetDelegate(this);
145 }
146
134 virtual ~AthenaWebView() { 147 virtual ~AthenaWebView() {
135 // |WebView| does not own the content, so we need to destroy it here. 148 // |WebView| does not own the content, so we need to destroy it here.
136 content::WebContents* current_contents = GetWebContents(); 149 content::WebContents* current_contents = GetWebContents();
137 SetWebContents(NULL); 150 SetWebContents(NULL);
138 delete current_contents; 151 delete current_contents;
139 } 152 }
140 153
141 void InstallAccelerators() { controller_->InstallAccelerators(); } 154 void InstallAccelerators() { controller_->InstallAccelerators(); }
142 155
143 void EvictContent() { 156 void EvictContent() {
(...skipping 10 matching lines...) Expand all
154 // TODO(skuhne): This breaks script connections with other activities. 167 // TODO(skuhne): This breaks script connections with other activities.
155 // Even though this is the same technique as used by the TabStripModel, 168 // Even though this is the same technique as used by the TabStripModel,
156 // we might want to address this cleaner since we are more likely to 169 // we might want to address this cleaner since we are more likely to
157 // run into this state. by unloading. 170 // run into this state. by unloading.
158 } 171 }
159 172
160 void ReloadContent() { 173 void ReloadContent() {
161 CHECK(evicted_web_contents_.get()); 174 CHECK(evicted_web_contents_.get());
162 content::WebContents* null_contents = GetWebContents(); 175 content::WebContents* null_contents = GetWebContents();
163 SetWebContents(evicted_web_contents_.release()); 176 SetWebContents(evicted_web_contents_.release());
177 web_contents()->SetDelegate(this);
164 delete null_contents; 178 delete null_contents;
165 } 179 }
166 180
167 // Check if the content got evicted. 181 // Check if the content got evicted.
168 const bool IsContentEvicted() { return !!evicted_web_contents_.get(); } 182 const bool IsContentEvicted() { return !!evicted_web_contents_.get(); }
169 183
170 private: 184 // content::WebContentsDelegate:
171 // WebContentsDelegate: 185 virtual content::WebContents* OpenURLFromTab(
186 content::WebContents* source,
187 const content::OpenURLParams& params) OVERRIDE {
188 switch(params.disposition) {
189 case CURRENT_TAB: {
190 DCHECK(source == web_contents());
191 content::NavigationController::LoadURLParams load_url_params(
192 params.url);
193 load_url_params.referrer = params.referrer;
194 load_url_params.frame_tree_node_id = params.frame_tree_node_id;
195 load_url_params.transition_type = params.transition;
196 load_url_params.extra_headers = params.extra_headers;
197 load_url_params.should_replace_current_entry =
198 params.should_replace_current_entry;
199 load_url_params.is_renderer_initiated = params.is_renderer_initiated;
200 load_url_params.transferred_global_request_id =
201 params.transferred_global_request_id;
202 web_contents()->GetController().LoadURLWithParams(load_url_params);
203 return web_contents();
204 }
205 case NEW_FOREGROUND_TAB:
oshima 2014/07/16 16:51:08 don't you have to handle NEW_BACKGROUND_TAB as wel
flackr 2014/07/18 18:15:08 Done.
206 case NEW_POPUP:
207 case NEW_WINDOW: {
208 ActivityManager::Get()->AddActivity(
209 ActivityFactory::Get()->CreateWebActivity(browser_context(),
210 params.url));
211 break;
212 }
213 default:
214 break;
215 }
216 // NULL is returned if the URL wasn't opened immediately.
217 return NULL;
218 }
219
220 virtual void AddNewContents(content::WebContents* source,
221 content::WebContents* new_contents,
222 WindowOpenDisposition disposition,
223 const gfx::Rect& initial_pos,
224 bool user_gesture,
225 bool* was_blocked) OVERRIDE {
226 ActivityManager::Get()->AddActivity(
227 new WebActivity(new AthenaWebView(new_contents)));
228 }
229
230 virtual void WebContentsFocused(content::WebContents* web_contents) OVERRIDE {
231 // Overridden because WebView expects to create and own its delegate but
232 // does not because it is owned here.
233 // TODO(flackr): Fix this since changes to WebView could introduce
234 // new WebContentsDelegate overrides which also expect to own the
235 // WebContents.
oshima 2014/07/16 16:51:08 Can't we just call OnWebContentsFocused()?
flackr 2014/07/18 18:15:08 Done. Though I'm still not sure why we require tha
236 }
237
172 virtual bool PreHandleKeyboardEvent( 238 virtual bool PreHandleKeyboardEvent(
173 content::WebContents* source, 239 content::WebContents* source,
174 const content::NativeWebKeyboardEvent& event, 240 const content::NativeWebKeyboardEvent& event,
175 bool* is_keyboard_shortcut) OVERRIDE { 241 bool* is_keyboard_shortcut) OVERRIDE {
176 return controller_->PreHandleKeyboardEvent( 242 return controller_->PreHandleKeyboardEvent(
177 source, event, is_keyboard_shortcut); 243 source, event, is_keyboard_shortcut);
178 } 244 }
179 245
180 virtual void HandleKeyboardEvent( 246 virtual void HandleKeyboardEvent(
181 content::WebContents* source, 247 content::WebContents* source,
182 const content::NativeWebKeyboardEvent& event) OVERRIDE { 248 const content::NativeWebKeyboardEvent& event) OVERRIDE {
183 controller_->HandleKeyboardEvent(source, event); 249 controller_->HandleKeyboardEvent(source, event);
184 } 250 }
185 251
252 virtual bool EmbedsFullscreenWidget() const OVERRIDE {
253 // Overridden because WebView expects to create and own its delegate but
254 // does not because it is owned here.
255 // TODO(flackr): Fix this since changes to WebView could introduce
256 // new WebContentsDelegate overrides which also expect to own the
257 // WebContents.
oshima 2014/07/16 16:51:08 Do you know why webview is checking wc_owner there
flackr 2014/07/18 18:15:08 Looking at the original CL it was always checked t
258 return false;
259 }
260
261 private:
186 scoped_ptr<WebActivityController> controller_; 262 scoped_ptr<WebActivityController> controller_;
187 263
188 // If the activity got evicted, this is the web content which holds the known 264 // If the activity got evicted, this is the web content which holds the known
189 // state of the content before eviction. 265 // state of the content before eviction.
190 scoped_ptr<content::WebContents> evicted_web_contents_; 266 scoped_ptr<content::WebContents> evicted_web_contents_;
191 267
192 DISALLOW_COPY_AND_ASSIGN(AthenaWebView); 268 DISALLOW_COPY_AND_ASSIGN(AthenaWebView);
193 }; 269 };
194 270
195 WebActivity::WebActivity(content::BrowserContext* browser_context, 271 WebActivity::WebActivity(content::BrowserContext* browser_context,
196 const GURL& url) 272 const GURL& url)
197 : browser_context_(browser_context), 273 : browser_context_(browser_context),
198 url_(url), 274 url_(url),
199 web_view_(NULL), 275 web_view_(NULL),
200 current_state_(ACTIVITY_UNLOADED) { 276 current_state_(ACTIVITY_UNLOADED) {
201 } 277 }
202 278
279 WebActivity::WebActivity(AthenaWebView* web_view)
280 : browser_context_(web_view->browser_context()),
281 url_(web_view->GetWebContents()->GetURL()),
282 web_view_(web_view),
283 current_state_(ACTIVITY_UNLOADED) {
284 // Transition to state ACTIVITY_INVISIBLE to perform the same setup steps
285 // as on new activities (namely adding a WebContentsObserver).
286 SetCurrentState(ACTIVITY_INVISIBLE);
287 }
288
203 WebActivity::~WebActivity() { 289 WebActivity::~WebActivity() {
204 // It is not required to change the activity state to UNLOADED - unless we 290 // It is not required to change the activity state to UNLOADED - unless we
205 // would add state observers. 291 // would add state observers.
206 } 292 }
207 293
208 ActivityViewModel* WebActivity::GetActivityViewModel() { 294 ActivityViewModel* WebActivity::GetActivityViewModel() {
209 return this; 295 return this;
210 } 296 }
211 297
212 void WebActivity::SetCurrentState(Activity::ActivityState state) { 298 void WebActivity::SetCurrentState(Activity::ActivityState state) {
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
309 bool explicit_set) { 395 bool explicit_set) {
310 ActivityManager::Get()->UpdateActivity(this); 396 ActivityManager::Get()->UpdateActivity(this);
311 } 397 }
312 398
313 void WebActivity::DidUpdateFaviconURL( 399 void WebActivity::DidUpdateFaviconURL(
314 const std::vector<content::FaviconURL>& candidates) { 400 const std::vector<content::FaviconURL>& candidates) {
315 ActivityManager::Get()->UpdateActivity(this); 401 ActivityManager::Get()->UpdateActivity(this);
316 } 402 }
317 403
318 } // namespace athena 404 } // namespace athena
OLDNEW
« no previous file with comments | « athena/content/web_activity.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698