OLD | NEW |
---|---|
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/tab_contents/tab_contents.h" | 5 #include "chrome/browser/tab_contents/tab_contents.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/auto_reset.h" | 9 #include "base/auto_reset.h" |
10 #include "base/metrics/histogram.h" | 10 #include "base/metrics/histogram.h" |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
241 params->current_history_list_length = controller.entry_count(); | 241 params->current_history_list_length = controller.entry_count(); |
242 params->url = entry.url(); | 242 params->url = entry.url(); |
243 params->referrer = entry.referrer(); | 243 params->referrer = entry.referrer(); |
244 params->transition = entry.transition_type(); | 244 params->transition = entry.transition_type(); |
245 params->state = entry.content_state(); | 245 params->state = entry.content_state(); |
246 params->navigation_type = | 246 params->navigation_type = |
247 GetNavigationType(controller.profile(), entry, reload_type); | 247 GetNavigationType(controller.profile(), entry, reload_type); |
248 params->request_time = base::Time::Now(); | 248 params->request_time = base::Time::Now(); |
249 } | 249 } |
250 | 250 |
251 // PluginInfoBar -------------------------------------------------------------- | |
251 | 252 |
252 // OutdatedPluginInfoBar ------------------------------------------------------ | 253 class PluginInfoBar : public ConfirmInfoBarDelegate { |
253 | |
254 class OutdatedPluginInfoBar : public ConfirmInfoBarDelegate { | |
255 public: | 254 public: |
256 OutdatedPluginInfoBar(TabContents* tab_contents, | 255 PluginInfoBar(TabContents* tab_contents, |
257 const string16& name, | 256 const string16& name, |
258 const GURL& update_url); | 257 const GURL& update_url); |
259 | |
260 private: | |
261 virtual ~OutdatedPluginInfoBar(); | |
262 | 258 |
263 // ConfirmInfoBarDelegate: | 259 // ConfirmInfoBarDelegate: |
264 virtual void InfoBarClosed(); | 260 virtual void InfoBarClosed(); |
265 virtual SkBitmap* GetIcon() const; | 261 virtual SkBitmap* GetIcon() const; |
266 virtual string16 GetMessageText() const; | 262 virtual string16 GetMessageText() const = 0; |
267 virtual int GetButtons() const; | 263 virtual int GetButtons() const = 0; |
268 virtual string16 GetButtonLabel(InfoBarButton button) const; | 264 virtual string16 GetButtonLabel(InfoBarButton button) const; |
269 virtual bool Accept(); | 265 virtual bool Accept(); |
270 virtual bool Cancel(); | 266 virtual bool Cancel(); |
271 virtual string16 GetLinkText(); | 267 virtual string16 GetLinkText(); |
272 virtual bool LinkClicked(WindowOpenDisposition disposition); | 268 virtual bool LinkClicked(WindowOpenDisposition disposition); |
273 | 269 |
270 protected: | |
271 virtual ~PluginInfoBar(); | |
272 | |
273 string16 name_; | |
274 | |
275 private: | |
276 virtual void RecordMetric(const std::string& action) const = 0; | |
277 | |
274 TabContents* tab_contents_; | 278 TabContents* tab_contents_; |
275 string16 name_; | |
276 GURL update_url_; | 279 GURL update_url_; |
280 | |
281 DISALLOW_COPY_AND_ASSIGN(PluginInfoBar); | |
282 }; | |
283 | |
284 PluginInfoBar::PluginInfoBar(TabContents* tab_contents, | |
285 const string16& name, | |
286 const GURL& update_url) | |
287 : ConfirmInfoBarDelegate(tab_contents), | |
288 name_(name), | |
289 tab_contents_(tab_contents), | |
290 update_url_(update_url) { | |
291 } | |
292 | |
293 PluginInfoBar::~PluginInfoBar() { | |
294 } | |
295 | |
296 void PluginInfoBar::InfoBarClosed() { | |
297 RecordMetric("Closed"); | |
298 delete this; | |
299 } | |
300 | |
301 SkBitmap* PluginInfoBar::GetIcon() const { | |
302 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
303 IDR_INFOBAR_PLUGIN_INSTALL); | |
304 } | |
305 | |
306 string16 PluginInfoBar::GetButtonLabel(InfoBarButton button) const { | |
307 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | |
308 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); | |
309 } | |
310 | |
311 bool PluginInfoBar::Accept() { | |
312 RecordMetric("Update"); | |
313 tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, | |
314 PageTransition::LINK); | |
315 return false; | |
316 } | |
317 | |
318 bool PluginInfoBar::Cancel() { | |
319 RecordMetric("AllowThisTime"); | |
320 tab_contents_->render_view_host()->LoadBlockedPlugins(); | |
321 return false; | |
322 } | |
323 | |
324 string16 PluginInfoBar::GetLinkText() { | |
325 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
326 } | |
327 | |
328 bool PluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { | |
329 RecordMetric("LearnMore"); | |
330 // TODO(bauerb): Navigate to a help page explaining why we disabled | |
331 // or blocked the plugin, once we have one. | |
332 return false; | |
333 } | |
334 | |
335 | |
336 // BlockedPluginInfoBar ------------------------------------------------------- | |
337 | |
338 class BlockedPluginInfoBar : public PluginInfoBar { | |
339 public: | |
340 BlockedPluginInfoBar(TabContents* tab_contents, | |
341 const string16& name); | |
342 | |
343 // ConfirmInfoBarDelegate: | |
344 virtual string16 GetMessageText() const; | |
345 virtual int GetButtons() const; | |
346 | |
347 protected: | |
348 virtual ~BlockedPluginInfoBar(); | |
349 | |
350 private: | |
351 // PluginInfoBar: | |
352 virtual void RecordMetric(const std::string& action) const; | |
353 | |
354 DISALLOW_COPY_AND_ASSIGN(BlockedPluginInfoBar); | |
355 }; | |
356 | |
357 BlockedPluginInfoBar::BlockedPluginInfoBar(TabContents* tab_contents, | |
358 const string16& name) | |
359 : PluginInfoBar(tab_contents, name, GURL()) { | |
360 tab_contents->AddInfoBar(this); | |
361 RecordMetric("Shown"); | |
362 } | |
363 | |
364 BlockedPluginInfoBar::~BlockedPluginInfoBar() { | |
365 } | |
366 | |
367 string16 BlockedPluginInfoBar::GetMessageText() const { | |
368 return l10n_util::GetStringFUTF16(IDS_PLUGIN_NOT_AUTHORIZED, name_); | |
369 } | |
370 | |
371 int BlockedPluginInfoBar::GetButtons() const { | |
372 return BUTTON_CANCEL; | |
373 } | |
374 | |
375 void BlockedPluginInfoBar::RecordMetric(const std::string& action) const { | |
376 std::string uma("BlockedPluginInfobar"); | |
377 uma += UTF16ToASCII(name_); | |
378 uma += "."; | |
379 uma += action; | |
380 UserMetrics::RecordAction(UserMetricsAction(uma.c_str())); | |
Bernhard Bauer
2011/01/24 12:56:33
The problem with this is if you don't use a string
| |
381 } | |
382 | |
383 // OutdatedPluginInfoBar ------------------------------------------------------ | |
384 | |
385 class OutdatedPluginInfoBar : public PluginInfoBar { | |
386 public: | |
387 OutdatedPluginInfoBar(TabContents* tab_contents, | |
388 const string16& name, | |
389 const GURL& update_url); | |
390 | |
391 // ConfirmInfoBarDelegate: | |
392 virtual string16 GetMessageText() const; | |
393 virtual int GetButtons() const; | |
394 | |
395 protected: | |
396 virtual ~OutdatedPluginInfoBar(); | |
397 | |
398 private: | |
399 // PluginInfoBar: | |
400 virtual void RecordMetric(const std::string& action) const; | |
401 | |
402 DISALLOW_COPY_AND_ASSIGN(OutdatedPluginInfoBar); | |
277 }; | 403 }; |
278 | 404 |
279 OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, | 405 OutdatedPluginInfoBar::OutdatedPluginInfoBar(TabContents* tab_contents, |
280 const string16& name, | 406 const string16& name, |
281 const GURL& update_url) | 407 const GURL& update_url) |
282 : ConfirmInfoBarDelegate(tab_contents), | 408 : PluginInfoBar(tab_contents, name, update_url) { |
283 tab_contents_(tab_contents), | |
284 name_(name), | |
285 update_url_(update_url) { | |
286 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Shown")); | |
287 tab_contents->AddInfoBar(this); | 409 tab_contents->AddInfoBar(this); |
410 RecordMetric("Shown"); | |
288 } | 411 } |
289 | 412 |
290 OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { | 413 OutdatedPluginInfoBar::~OutdatedPluginInfoBar() { |
291 } | 414 } |
292 | 415 |
293 void OutdatedPluginInfoBar::InfoBarClosed() { | |
294 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Closed")); | |
295 delete this; | |
296 } | |
297 | |
298 SkBitmap* OutdatedPluginInfoBar::GetIcon() const { | |
299 return ResourceBundle::GetSharedInstance().GetBitmapNamed( | |
300 IDR_INFOBAR_PLUGIN_INSTALL); | |
301 } | |
302 | |
303 string16 OutdatedPluginInfoBar::GetMessageText() const { | 416 string16 OutdatedPluginInfoBar::GetMessageText() const { |
304 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); | 417 return l10n_util::GetStringFUTF16(IDS_PLUGIN_OUTDATED_PROMPT, name_); |
305 } | 418 } |
306 | 419 |
307 int OutdatedPluginInfoBar::GetButtons() const { | 420 int OutdatedPluginInfoBar::GetButtons() const { |
308 return BUTTON_OK | BUTTON_CANCEL; | 421 return BUTTON_OK | BUTTON_CANCEL; |
309 } | 422 } |
310 | 423 |
311 string16 OutdatedPluginInfoBar::GetButtonLabel(InfoBarButton button) const { | 424 void OutdatedPluginInfoBar::RecordMetric(const std::string& action) const { |
312 return l10n_util::GetStringUTF16((button == BUTTON_OK) ? | 425 std::string uma("OutdatedPluginInfobar."); |
313 IDS_PLUGIN_UPDATE : IDS_PLUGIN_ENABLE_TEMPORARILY); | 426 uma += action; |
314 } | 427 UserMetrics::RecordAction(UserMetricsAction(uma.c_str())); |
315 | |
316 bool OutdatedPluginInfoBar::Accept() { | |
317 UserMetrics::RecordAction(UserMetricsAction("OutdatedPluginInfobar.Update")); | |
318 tab_contents_->OpenURL(update_url_, GURL(), NEW_FOREGROUND_TAB, | |
319 PageTransition::LINK); | |
320 return false; | |
321 } | |
322 | |
323 bool OutdatedPluginInfoBar::Cancel() { | |
324 UserMetrics::RecordAction( | |
325 UserMetricsAction("OutdatedPluginInfobar.AllowThisTime")); | |
326 tab_contents_->render_view_host()->LoadBlockedPlugins(); | |
327 return false; | |
328 } | |
329 | |
330 string16 OutdatedPluginInfoBar::GetLinkText() { | |
331 return l10n_util::GetStringUTF16(IDS_LEARN_MORE); | |
332 } | |
333 | |
334 bool OutdatedPluginInfoBar::LinkClicked(WindowOpenDisposition disposition) { | |
335 UserMetrics::RecordAction( | |
336 UserMetricsAction("OutdatedPluginInfobar.LearnMore")); | |
337 // TODO(bauerb): Navigate to a help page explaining why we disabled | |
338 // the plugin, once we have one. | |
339 return false; | |
340 } | 428 } |
341 | 429 |
342 } // namespace | 430 } // namespace |
343 | 431 |
344 | 432 |
345 // TabContents ---------------------------------------------------------------- | 433 // TabContents ---------------------------------------------------------------- |
346 | 434 |
347 // static | 435 // static |
348 int TabContents::find_request_id_counter_ = -1; | 436 int TabContents::find_request_id_counter_ = -1; |
349 | 437 |
(...skipping 1993 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
2343 delegate()->OnDidGetApplicationInfo(this, page_id); | 2431 delegate()->OnDidGetApplicationInfo(this, page_id); |
2344 } | 2432 } |
2345 | 2433 |
2346 void TabContents::OnInstallApplication(const WebApplicationInfo& info) { | 2434 void TabContents::OnInstallApplication(const WebApplicationInfo& info) { |
2347 if (delegate()) | 2435 if (delegate()) |
2348 delegate()->OnInstallApplication(this, info); | 2436 delegate()->OnInstallApplication(this, info); |
2349 } | 2437 } |
2350 | 2438 |
2351 void TabContents::OnBlockedOutdatedPlugin(const string16& name, | 2439 void TabContents::OnBlockedOutdatedPlugin(const string16& name, |
2352 const GURL& update_url) { | 2440 const GURL& update_url) { |
2353 new OutdatedPluginInfoBar(this, name, update_url); | 2441 if (!update_url.is_empty()) |
2442 new OutdatedPluginInfoBar(this, name, update_url); | |
2443 else | |
2444 new BlockedPluginInfoBar(this, name); | |
2354 } | 2445 } |
2355 | 2446 |
2356 void TabContents::OnPageContents(const GURL& url, | 2447 void TabContents::OnPageContents(const GURL& url, |
2357 int renderer_process_id, | 2448 int renderer_process_id, |
2358 int32 page_id, | 2449 int32 page_id, |
2359 const string16& contents, | 2450 const string16& contents, |
2360 const std::string& language, | 2451 const std::string& language, |
2361 bool page_translatable) { | 2452 bool page_translatable) { |
2362 // Don't index any https pages. People generally don't want their bank | 2453 // Don't index any https pages. People generally don't want their bank |
2363 // accounts, etc. indexed on their computer, especially since some of these | 2454 // accounts, etc. indexed on their computer, especially since some of these |
(...skipping 1017 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
3381 if (pm != NULL) { | 3472 if (pm != NULL) { |
3382 if (pm->MaybeUsePreloadedPage(this, url)) { | 3473 if (pm->MaybeUsePreloadedPage(this, url)) { |
3383 // TODO(tburkard): If the preloaded page has not finished preloading | 3474 // TODO(tburkard): If the preloaded page has not finished preloading |
3384 // yet, we should not do this. | 3475 // yet, we should not do this. |
3385 DidStopLoading(); | 3476 DidStopLoading(); |
3386 return true; | 3477 return true; |
3387 } | 3478 } |
3388 } | 3479 } |
3389 return false; | 3480 return false; |
3390 } | 3481 } |
OLD | NEW |