| 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 // 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" |
| (...skipping 804 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 815 | 815 |
| 816 if (frame_id == 0) | 816 if (frame_id == 0) |
| 817 frame_id = frame_navigation_state.GetMainFrameID(); | 817 frame_id = frame_navigation_state.GetMainFrameID(); |
| 818 if (!frame_navigation_state.IsValidFrame(frame_id)) | 818 if (!frame_navigation_state.IsValidFrame(frame_id)) |
| 819 return true; | 819 return true; |
| 820 | 820 |
| 821 GURL frame_url = frame_navigation_state.GetUrl(frame_id); | 821 GURL frame_url = frame_navigation_state.GetUrl(frame_id); |
| 822 if (!frame_navigation_state.IsValidUrl(frame_url)) | 822 if (!frame_navigation_state.IsValidUrl(frame_url)) |
| 823 return true; | 823 return true; |
| 824 | 824 |
| 825 GetFrame::Result::Details frame_details; | 825 GetFrame::Results::Details frame_details; |
| 826 frame_details.url = frame_url.spec(); | 826 frame_details.url = frame_url.spec(); |
| 827 frame_details.error_occurred = | 827 frame_details.error_occurred = |
| 828 frame_navigation_state.GetErrorOccurredInFrame(frame_id); | 828 frame_navigation_state.GetErrorOccurredInFrame(frame_id); |
| 829 SetResult(GetFrame::Result::Create(frame_details)); | 829 results_ = GetFrame::Results::Create(frame_details); |
| 830 return true; | 830 return true; |
| 831 } | 831 } |
| 832 | 832 |
| 833 bool GetAllFramesFunction::RunImpl() { | 833 bool GetAllFramesFunction::RunImpl() { |
| 834 scoped_ptr<GetAllFrames::Params> params(GetAllFrames::Params::Create(*args_)); | 834 scoped_ptr<GetAllFrames::Params> params(GetAllFrames::Params::Create(*args_)); |
| 835 EXTENSION_FUNCTION_VALIDATE(params.get()); | 835 EXTENSION_FUNCTION_VALIDATE(params.get()); |
| 836 int tab_id = params->details.tab_id; | 836 int tab_id = params->details.tab_id; |
| 837 | 837 |
| 838 SetResult(Value::CreateNullValue()); | 838 SetResult(Value::CreateNullValue()); |
| 839 | 839 |
| 840 TabContents* tab_contents; | 840 TabContents* tab_contents; |
| 841 if (!ExtensionTabUtil::GetTabById(tab_id, | 841 if (!ExtensionTabUtil::GetTabById(tab_id, |
| 842 profile(), | 842 profile(), |
| 843 include_incognito(), | 843 include_incognito(), |
| 844 NULL, NULL, | 844 NULL, NULL, |
| 845 &tab_contents, | 845 &tab_contents, |
| 846 NULL) || | 846 NULL) || |
| 847 !tab_contents) { | 847 !tab_contents) { |
| 848 return true; | 848 return true; |
| 849 } | 849 } |
| 850 | 850 |
| 851 WebContents* web_contents = tab_contents->web_contents(); | 851 WebContents* web_contents = tab_contents->web_contents(); |
| 852 WebNavigationTabObserver* observer = | 852 WebNavigationTabObserver* observer = |
| 853 WebNavigationTabObserver::Get(web_contents); | 853 WebNavigationTabObserver::Get(web_contents); |
| 854 DCHECK(observer); | 854 DCHECK(observer); |
| 855 | 855 |
| 856 const FrameNavigationState& navigation_state = | 856 const FrameNavigationState& navigation_state = |
| 857 observer->frame_navigation_state(); | 857 observer->frame_navigation_state(); |
| 858 | 858 |
| 859 std::vector<linked_ptr<GetAllFrames::Result::DetailsElement> > result_list; | 859 std::vector<linked_ptr<GetAllFrames::Results::DetailsElement> > result_list; |
| 860 for (FrameNavigationState::const_iterator it = navigation_state.begin(); | 860 for (FrameNavigationState::const_iterator it = navigation_state.begin(); |
| 861 it != navigation_state.end(); ++it) { | 861 it != navigation_state.end(); ++it) { |
| 862 int64 frame_id = *it; | 862 int64 frame_id = *it; |
| 863 GURL frame_url = navigation_state.GetUrl(frame_id); | 863 GURL frame_url = navigation_state.GetUrl(frame_id); |
| 864 if (!navigation_state.IsValidUrl(frame_url)) | 864 if (!navigation_state.IsValidUrl(frame_url)) |
| 865 continue; | 865 continue; |
| 866 linked_ptr<GetAllFrames::Result::DetailsElement> frame( | 866 linked_ptr<GetAllFrames::Results::DetailsElement> frame( |
| 867 new GetAllFrames::Result::DetailsElement()); | 867 new GetAllFrames::Results::DetailsElement()); |
| 868 frame->url = frame_url.spec(); | 868 frame->url = frame_url.spec(); |
| 869 frame->frame_id = GetFrameId(navigation_state.IsMainFrame(frame_id), | 869 frame->frame_id = GetFrameId(navigation_state.IsMainFrame(frame_id), |
| 870 frame_id); | 870 frame_id); |
| 871 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); | 871 frame->error_occurred = navigation_state.GetErrorOccurredInFrame(frame_id); |
| 872 result_list.push_back(frame); | 872 result_list.push_back(frame); |
| 873 } | 873 } |
| 874 SetResult(GetAllFrames::Result::Create(result_list)); | 874 results_ = GetAllFrames::Results::Create(result_list); |
| 875 return true; | 875 return true; |
| 876 } | 876 } |
| 877 | 877 |
| 878 } // namespace extensions | 878 } // namespace extensions |
| OLD | NEW |