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

Side by Side Diff: chrome/browser/extensions/api/web_navigation/web_navigation_api.cc

Issue 10535077: TabContentsWrapper -> TabContents, part 12. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years, 6 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
OLDNEW
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 // Implements the Chrome Extensions WebNavigation API. 5 // Implements the Chrome Extensions WebNavigation API.
6 6
7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h" 7 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api.h"
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
11 #include "base/string_number_conversions.h" 11 #include "base/string_number_conversions.h"
12 #include "base/time.h" 12 #include "base/time.h"
13 #include "base/values.h" 13 #include "base/values.h"
14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h" 14 #include "chrome/browser/extensions/api/web_navigation/web_navigation_api_consta nts.h"
15 #include "chrome/browser/extensions/extension_event_router.h" 15 #include "chrome/browser/extensions/extension_event_router.h"
16 #include "chrome/browser/extensions/extension_tab_util.h" 16 #include "chrome/browser/extensions/extension_tab_util.h"
17 #include "chrome/browser/profiles/profile.h" 17 #include "chrome/browser/profiles/profile.h"
18 #include "chrome/browser/tab_contents/retargeting_details.h" 18 #include "chrome/browser/tab_contents/retargeting_details.h"
19 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 19 #include "chrome/browser/ui/tab_contents/tab_contents.h"
20 #include "chrome/browser/view_type_utils.h" 20 #include "chrome/browser/view_type_utils.h"
21 #include "chrome/common/chrome_notification_types.h" 21 #include "chrome/common/chrome_notification_types.h"
22 #include "chrome/common/url_constants.h" 22 #include "chrome/common/url_constants.h"
23 #include "content/public/browser/resource_request_details.h" 23 #include "content/public/browser/resource_request_details.h"
24 #include "content/public/browser/navigation_details.h" 24 #include "content/public/browser/navigation_details.h"
25 #include "content/public/browser/notification_service.h" 25 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h" 26 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/render_view_host.h" 27 #include "content/public/browser/render_view_host.h"
28 #include "content/public/browser/web_contents.h" 28 #include "content/public/browser/web_contents.h"
29 #include "net/base/net_errors.h" 29 #include "net/base/net_errors.h"
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 chrome::VIEW_TYPE_TAB_CONTENTS); 451 chrome::VIEW_TYPE_TAB_CONTENTS);
452 return; 452 return;
453 } 453 }
454 const FrameNavigationState& frame_navigation_state = 454 const FrameNavigationState& frame_navigation_state =
455 tab_observer->frame_navigation_state(); 455 tab_observer->frame_navigation_state();
456 456
457 if (!frame_navigation_state.CanSendEvents(details->source_frame_id)) 457 if (!frame_navigation_state.CanSendEvents(details->source_frame_id))
458 return; 458 return;
459 459
460 // If the WebContents was created as a response to an IPC from a renderer 460 // If the WebContents was created as a response to an IPC from a renderer
461 // (and therefore doesn't yet have a wrapper), or if it isn't yet inserted 461 // (and therefore doesn't yet have a TabContents), or if it isn't yet inserted
462 // into a tab strip, we need to delay the extension event until the 462 // into a tab strip, we need to delay the extension event until the
463 // WebContents is fully initialized. 463 // WebContents is fully initialized.
464 if ((TabContentsWrapper::GetCurrentWrapperForContents( 464 if (TabContents::FromWebContents(details->target_web_contents) == NULL ||
465 details->target_web_contents) == NULL) ||
466 details->not_yet_in_tabstrip) { 465 details->not_yet_in_tabstrip) {
467 pending_web_contents_[details->target_web_contents] = 466 pending_web_contents_[details->target_web_contents] =
468 PendingWebContents( 467 PendingWebContents(
469 details->source_web_contents, 468 details->source_web_contents,
470 details->source_frame_id, 469 details->source_frame_id,
471 frame_navigation_state.IsMainFrame(details->source_frame_id), 470 frame_navigation_state.IsMainFrame(details->source_frame_id),
472 details->target_web_contents, 471 details->target_web_contents,
473 details->target_url); 472 details->target_url);
474 } else { 473 } else {
475 DispatchOnCreatedNavigationTarget( 474 DispatchOnCreatedNavigationTarget(
(...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after
724 DCHECK(details); 723 DCHECK(details);
725 724
726 int tab_id; 725 int tab_id;
727 int frame_id; 726 int frame_id;
728 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id)); 727 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id));
729 EXTENSION_FUNCTION_VALIDATE( 728 EXTENSION_FUNCTION_VALIDATE(
730 details->GetInteger(keys::kFrameIdKey, &frame_id)); 729 details->GetInteger(keys::kFrameIdKey, &frame_id));
731 730
732 result_.reset(Value::CreateNullValue()); 731 result_.reset(Value::CreateNullValue());
733 732
734 TabContentsWrapper* wrapper; 733 TabContents* tab_contents;
735 if (!ExtensionTabUtil::GetTabById( 734 if (!ExtensionTabUtil::GetTabById(tab_id,
736 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) || 735 profile(),
737 !wrapper) { 736 include_incognito(),
737 NULL, NULL,
738 &tab_contents,
739 NULL) ||
740 !tab_contents) {
738 return true; 741 return true;
739 } 742 }
740 743
741 WebContents* web_contents = wrapper->web_contents(); 744 WebContents* web_contents = tab_contents->web_contents();
742 WebNavigationTabObserver* observer = 745 WebNavigationTabObserver* observer =
743 WebNavigationTabObserver::Get(web_contents); 746 WebNavigationTabObserver::Get(web_contents);
744 DCHECK(observer); 747 DCHECK(observer);
745 748
746 const FrameNavigationState& frame_navigation_state = 749 const FrameNavigationState& frame_navigation_state =
747 observer->frame_navigation_state(); 750 observer->frame_navigation_state();
748 751
749 if (frame_id == 0) 752 if (frame_id == 0)
750 frame_id = frame_navigation_state.GetMainFrameID(); 753 frame_id = frame_navigation_state.GetMainFrameID();
751 if (!frame_navigation_state.IsValidFrame(frame_id)) 754 if (!frame_navigation_state.IsValidFrame(frame_id))
(...skipping 15 matching lines...) Expand all
767 bool GetAllFramesFunction::RunImpl() { 770 bool GetAllFramesFunction::RunImpl() {
768 DictionaryValue* details; 771 DictionaryValue* details;
769 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details)); 772 EXTENSION_FUNCTION_VALIDATE(args_->GetDictionary(0, &details));
770 DCHECK(details); 773 DCHECK(details);
771 774
772 int tab_id; 775 int tab_id;
773 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id)); 776 EXTENSION_FUNCTION_VALIDATE(details->GetInteger(keys::kTabIdKey, &tab_id));
774 777
775 result_.reset(Value::CreateNullValue()); 778 result_.reset(Value::CreateNullValue());
776 779
777 TabContentsWrapper* wrapper; 780 TabContents* tab_contents;
778 if (!ExtensionTabUtil::GetTabById( 781 if (!ExtensionTabUtil::GetTabById(tab_id,
779 tab_id, profile(), include_incognito(), NULL, NULL, &wrapper, NULL) || 782 profile(),
780 !wrapper) { 783 include_incognito(),
784 NULL, NULL,
785 &tab_contents,
786 NULL) ||
787 !tab_contents) {
781 return true; 788 return true;
782 } 789 }
783 790
784 WebContents* web_contents = wrapper->web_contents(); 791 WebContents* web_contents = tab_contents->web_contents();
785 WebNavigationTabObserver* observer = 792 WebNavigationTabObserver* observer =
786 WebNavigationTabObserver::Get(web_contents); 793 WebNavigationTabObserver::Get(web_contents);
787 DCHECK(observer); 794 DCHECK(observer);
788 795
789 const FrameNavigationState& navigation_state = 796 const FrameNavigationState& navigation_state =
790 observer->frame_navigation_state(); 797 observer->frame_navigation_state();
791 798
792 ListValue* resultList = new ListValue(); 799 ListValue* resultList = new ListValue();
793 for (FrameNavigationState::const_iterator frame = navigation_state.begin(); 800 for (FrameNavigationState::const_iterator frame = navigation_state.begin();
794 frame != navigation_state.end(); ++frame) { 801 frame != navigation_state.end(); ++frame) {
795 GURL frame_url = navigation_state.GetUrl(*frame); 802 GURL frame_url = navigation_state.GetUrl(*frame);
796 if (!navigation_state.IsValidUrl(frame_url)) 803 if (!navigation_state.IsValidUrl(frame_url))
797 continue; 804 continue;
798 DictionaryValue* frameDict = new DictionaryValue(); 805 DictionaryValue* frameDict = new DictionaryValue();
799 frameDict->SetString(keys::kUrlKey, frame_url.spec()); 806 frameDict->SetString(keys::kUrlKey, frame_url.spec());
800 frameDict->SetInteger( 807 frameDict->SetInteger(
801 keys::kFrameIdKey, 808 keys::kFrameIdKey,
802 GetFrameId(navigation_state.IsMainFrame(*frame), *frame)); 809 GetFrameId(navigation_state.IsMainFrame(*frame), *frame));
803 frameDict->SetBoolean( 810 frameDict->SetBoolean(
804 keys::kErrorOccurredKey, 811 keys::kErrorOccurredKey,
805 navigation_state.GetErrorOccurredInFrame(*frame)); 812 navigation_state.GetErrorOccurredInFrame(*frame));
806 resultList->Append(frameDict); 813 resultList->Append(frameDict);
807 } 814 }
808 result_.reset(resultList); 815 result_.reset(resultList);
809 return true; 816 return true;
810 } 817 }
811 818
812 } // namespace extensions 819 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/browser/extensions/api/tabs/tabs.cc ('k') | chrome/browser/extensions/api/web_navigation/web_navigation_apitest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698