OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/extensions/extension_tab_util.h" | 5 #include "chrome/browser/extensions/extension_tab_util.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include "base/macros.h" | 9 #include "base/macros.h" |
10 #include "base/strings/string_number_conversions.h" | 10 #include "base/strings/string_number_conversions.h" |
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
324 | 324 |
325 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { | 325 std::string ExtensionTabUtil::GetTabStatusText(bool is_loading) { |
326 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; | 326 return is_loading ? keys::kStatusValueLoading : keys::kStatusValueComplete; |
327 } | 327 } |
328 | 328 |
329 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { | 329 int ExtensionTabUtil::GetWindowIdOfTab(const WebContents* web_contents) { |
330 return SessionTabHelper::IdForWindowContainingTab(web_contents); | 330 return SessionTabHelper::IdForWindowContainingTab(web_contents); |
331 } | 331 } |
332 | 332 |
333 // static | 333 // static |
334 scoped_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( | 334 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( |
335 WebContents* contents, | 335 WebContents* contents, |
336 TabStripModel* tab_strip, | 336 TabStripModel* tab_strip, |
337 int tab_index, | 337 int tab_index, |
338 const Extension* extension) { | 338 const Extension* extension) { |
339 // If we have a matching AppWindow with a controller, get the tab value | 339 // If we have a matching AppWindow with a controller, get the tab value |
340 // from its controller instead. | 340 // from its controller instead. |
341 WindowController* controller = GetAppWindowController(contents); | 341 WindowController* controller = GetAppWindowController(contents); |
342 if (controller && | 342 if (controller && |
343 (!extension || controller->IsVisibleToExtension(extension))) { | 343 (!extension || controller->IsVisibleToExtension(extension))) { |
344 return controller->CreateTabObject(extension, tab_index); | 344 return controller->CreateTabObject(extension, tab_index); |
345 } | 345 } |
346 scoped_ptr<api::tabs::Tab> result = | 346 std::unique_ptr<api::tabs::Tab> result = |
347 CreateTabObject(contents, tab_strip, tab_index); | 347 CreateTabObject(contents, tab_strip, tab_index); |
348 ScrubTabForExtension(extension, contents, result.get()); | 348 ScrubTabForExtension(extension, contents, result.get()); |
349 return result; | 349 return result; |
350 } | 350 } |
351 | 351 |
352 base::ListValue* ExtensionTabUtil::CreateTabList( | 352 base::ListValue* ExtensionTabUtil::CreateTabList( |
353 const Browser* browser, | 353 const Browser* browser, |
354 const Extension* extension) { | 354 const Extension* extension) { |
355 base::ListValue* tab_list = new base::ListValue(); | 355 base::ListValue* tab_list = new base::ListValue(); |
356 TabStripModel* tab_strip = browser->tab_strip_model(); | 356 TabStripModel* tab_strip = browser->tab_strip_model(); |
357 for (int i = 0; i < tab_strip->count(); ++i) { | 357 for (int i = 0; i < tab_strip->count(); ++i) { |
358 tab_list->Append( | 358 tab_list->Append( |
359 CreateTabObject(tab_strip->GetWebContentsAt(i), tab_strip, i, extension) | 359 CreateTabObject(tab_strip->GetWebContentsAt(i), tab_strip, i, extension) |
360 ->ToValue() | 360 ->ToValue() |
361 .release()); | 361 .release()); |
362 } | 362 } |
363 | 363 |
364 return tab_list; | 364 return tab_list; |
365 } | 365 } |
366 | 366 |
367 // static | 367 // static |
368 scoped_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( | 368 std::unique_ptr<api::tabs::Tab> ExtensionTabUtil::CreateTabObject( |
369 content::WebContents* contents, | 369 content::WebContents* contents, |
370 TabStripModel* tab_strip, | 370 TabStripModel* tab_strip, |
371 int tab_index) { | 371 int tab_index) { |
372 // If we have a matching AppWindow with a controller, get the tab value | 372 // If we have a matching AppWindow with a controller, get the tab value |
373 // from its controller instead. | 373 // from its controller instead. |
374 WindowController* controller = GetAppWindowController(contents); | 374 WindowController* controller = GetAppWindowController(contents); |
375 if (controller) | 375 if (controller) |
376 return controller->CreateTabObject(nullptr, tab_index); | 376 return controller->CreateTabObject(nullptr, tab_index); |
377 | 377 |
378 if (!tab_strip) | 378 if (!tab_strip) |
379 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); | 379 ExtensionTabUtil::GetTabStripModel(contents, &tab_strip, &tab_index); |
380 bool is_loading = contents->IsLoading(); | 380 bool is_loading = contents->IsLoading(); |
381 scoped_ptr<api::tabs::Tab> tab_object(new api::tabs::Tab); | 381 std::unique_ptr<api::tabs::Tab> tab_object(new api::tabs::Tab); |
382 tab_object->id.reset(new int(GetTabIdForExtensions(contents))); | 382 tab_object->id.reset(new int(GetTabIdForExtensions(contents))); |
383 tab_object->index = tab_index; | 383 tab_object->index = tab_index; |
384 tab_object->window_id = GetWindowIdOfTab(contents); | 384 tab_object->window_id = GetWindowIdOfTab(contents); |
385 tab_object->status.reset(new std::string(GetTabStatusText(is_loading))); | 385 tab_object->status.reset(new std::string(GetTabStatusText(is_loading))); |
386 tab_object->active = tab_strip && tab_index == tab_strip->active_index(); | 386 tab_object->active = tab_strip && tab_index == tab_strip->active_index(); |
387 tab_object->selected = tab_strip && tab_index == tab_strip->active_index(); | 387 tab_object->selected = tab_strip && tab_index == tab_strip->active_index(); |
388 tab_object->highlighted = tab_strip && tab_strip->IsTabSelected(tab_index); | 388 tab_object->highlighted = tab_strip && tab_strip->IsTabSelected(tab_index); |
389 tab_object->pinned = tab_strip && tab_strip->IsTabPinned(tab_index); | 389 tab_object->pinned = tab_strip && tab_strip->IsTabPinned(tab_index); |
390 tab_object->audible.reset(new bool(contents->WasRecentlyAudible())); | 390 tab_object->audible.reset(new bool(contents->WasRecentlyAudible())); |
391 tab_object->muted_info = CreateMutedInfo(contents); | 391 tab_object->muted_info = CreateMutedInfo(contents); |
(...skipping 13 matching lines...) Expand all Loading... |
405 if (tab_strip) { | 405 if (tab_strip) { |
406 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); | 406 WebContents* opener = tab_strip->GetOpenerOfWebContentsAt(tab_index); |
407 if (opener) | 407 if (opener) |
408 tab_object->opener_tab_id.reset(new int(GetTabIdForExtensions(opener))); | 408 tab_object->opener_tab_id.reset(new int(GetTabIdForExtensions(opener))); |
409 } | 409 } |
410 | 410 |
411 return tab_object; | 411 return tab_object; |
412 } | 412 } |
413 | 413 |
414 // static | 414 // static |
415 scoped_ptr<api::tabs::MutedInfo> ExtensionTabUtil::CreateMutedInfo( | 415 std::unique_ptr<api::tabs::MutedInfo> ExtensionTabUtil::CreateMutedInfo( |
416 content::WebContents* contents) { | 416 content::WebContents* contents) { |
417 DCHECK(contents); | 417 DCHECK(contents); |
418 scoped_ptr<api::tabs::MutedInfo> info(new api::tabs::MutedInfo); | 418 std::unique_ptr<api::tabs::MutedInfo> info(new api::tabs::MutedInfo); |
419 info->muted = contents->IsAudioMuted(); | 419 info->muted = contents->IsAudioMuted(); |
420 switch (chrome::GetTabAudioMutedReason(contents)) { | 420 switch (chrome::GetTabAudioMutedReason(contents)) { |
421 case TabMutedReason::NONE: | 421 case TabMutedReason::NONE: |
422 break; | 422 break; |
423 case TabMutedReason::CONTEXT_MENU: | 423 case TabMutedReason::CONTEXT_MENU: |
424 case TabMutedReason::AUDIO_INDICATOR: | 424 case TabMutedReason::AUDIO_INDICATOR: |
425 info->reason = api::tabs::MUTED_INFO_REASON_USER; | 425 info->reason = api::tabs::MUTED_INFO_REASON_USER; |
426 break; | 426 break; |
427 case TabMutedReason::MEDIA_CAPTURE: | 427 case TabMutedReason::MEDIA_CAPTURE: |
428 info->reason = api::tabs::MUTED_INFO_REASON_CAPTURE; | 428 info->reason = api::tabs::MUTED_INFO_REASON_CAPTURE; |
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
620 return NULL; | 620 return NULL; |
621 } | 621 } |
622 | 622 |
623 bool ExtensionTabUtil::OpenOptionsPage(const Extension* extension, | 623 bool ExtensionTabUtil::OpenOptionsPage(const Extension* extension, |
624 Browser* browser) { | 624 Browser* browser) { |
625 if (!OptionsPageInfo::HasOptionsPage(extension)) | 625 if (!OptionsPageInfo::HasOptionsPage(extension)) |
626 return false; | 626 return false; |
627 | 627 |
628 // Force the options page to open in non-OTR window, because it won't be | 628 // Force the options page to open in non-OTR window, because it won't be |
629 // able to save settings from OTR. | 629 // able to save settings from OTR. |
630 scoped_ptr<chrome::ScopedTabbedBrowserDisplayer> displayer; | 630 std::unique_ptr<chrome::ScopedTabbedBrowserDisplayer> displayer; |
631 if (browser->profile()->IsOffTheRecord()) { | 631 if (browser->profile()->IsOffTheRecord()) { |
632 displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( | 632 displayer.reset(new chrome::ScopedTabbedBrowserDisplayer( |
633 browser->profile()->GetOriginalProfile())); | 633 browser->profile()->GetOriginalProfile())); |
634 browser = displayer->browser(); | 634 browser = displayer->browser(); |
635 } | 635 } |
636 | 636 |
637 GURL url_to_navigate; | 637 GURL url_to_navigate; |
638 bool open_in_tab = OptionsPageInfo::ShouldOpenInTab(extension); | 638 bool open_in_tab = OptionsPageInfo::ShouldOpenInTab(extension); |
639 if (open_in_tab) { | 639 if (open_in_tab) { |
640 // Options page tab is simply e.g. chrome-extension://.../options.html. | 640 // Options page tab is simply e.g. chrome-extension://.../options.html. |
(...skipping 23 matching lines...) Expand all Loading... |
664 chrome::ShowSingletonTabOverwritingNTP(browser, params); | 664 chrome::ShowSingletonTabOverwritingNTP(browser, params); |
665 return true; | 665 return true; |
666 } | 666 } |
667 | 667 |
668 // static | 668 // static |
669 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { | 669 bool ExtensionTabUtil::BrowserSupportsTabs(Browser* browser) { |
670 return browser && browser->tab_strip_model() && !browser->is_devtools(); | 670 return browser && browser->tab_strip_model() && !browser->is_devtools(); |
671 } | 671 } |
672 | 672 |
673 } // namespace extensions | 673 } // namespace extensions |
OLD | NEW |