| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 "content/renderer/render_frame_impl.h" | 5 #include "content/renderer/render_frame_impl.h" |
| 6 | 6 |
| 7 #include <map> | 7 #include <map> |
| 8 #include <string> | 8 #include <string> |
| 9 #include <utility> | 9 #include <utility> |
| 10 #include <vector> | 10 #include <vector> |
| (...skipping 889 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 900 } | 900 } |
| 901 | 901 |
| 902 struct RenderFrameImpl::PendingFileChooser { | 902 struct RenderFrameImpl::PendingFileChooser { |
| 903 PendingFileChooser(const FileChooserParams& p, | 903 PendingFileChooser(const FileChooserParams& p, |
| 904 blink::WebFileChooserCompletion* c) | 904 blink::WebFileChooserCompletion* c) |
| 905 : params(p), completion(c) {} | 905 : params(p), completion(c) {} |
| 906 FileChooserParams params; | 906 FileChooserParams params; |
| 907 blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. | 907 blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 908 }; | 908 }; |
| 909 | 909 |
| 910 const std::string& UniqueNameForWebFrame(blink::WebFrame* frame) { |
| 911 return frame->IsWebLocalFrame() |
| 912 ? RenderFrameImpl::FromWebFrame(frame)->unique_name() |
| 913 : RenderFrameProxy::FromWebFrame(frame)->unique_name(); |
| 914 } |
| 915 |
| 916 RenderFrameImpl::UniqueNameFrameAdapter::UniqueNameFrameAdapter( |
| 917 RenderFrameImpl* render_frame) |
| 918 : render_frame_(render_frame) {} |
| 919 |
| 920 RenderFrameImpl::UniqueNameFrameAdapter::~UniqueNameFrameAdapter() {} |
| 921 |
| 922 bool RenderFrameImpl::UniqueNameFrameAdapter::IsMainFrame() const { |
| 923 return render_frame_->IsMainFrame(); |
| 924 } |
| 925 |
| 926 bool RenderFrameImpl::UniqueNameFrameAdapter::IsCandidateUnique( |
| 927 const std::string& name) const { |
| 928 // This method is currently O(N), where N = number of frames in the tree. |
| 929 DCHECK(!name.empty()); |
| 930 |
| 931 for (blink::WebFrame* frame = GetWebFrame()->Top(); frame; |
| 932 frame = frame->TraverseNext()) { |
| 933 if (UniqueNameForWebFrame(frame) == name) |
| 934 return false; |
| 935 } |
| 936 |
| 937 return true; |
| 938 } |
| 939 |
| 940 int RenderFrameImpl::UniqueNameFrameAdapter::GetSiblingCount() const { |
| 941 int sibling_count = 0; |
| 942 for (blink::WebFrame* frame = GetWebFrame()->Parent()->FirstChild(); frame; |
| 943 frame = frame->NextSibling()) { |
| 944 if (frame == GetWebFrame()) |
| 945 continue; |
| 946 ++sibling_count; |
| 947 } |
| 948 return sibling_count; |
| 949 } |
| 950 |
| 951 int RenderFrameImpl::UniqueNameFrameAdapter::GetChildCount() const { |
| 952 int child_count = 0; |
| 953 for (blink::WebFrame* frame = GetWebFrame()->FirstChild(); frame; |
| 954 frame = frame->NextSibling()) { |
| 955 ++child_count; |
| 956 } |
| 957 return child_count; |
| 958 } |
| 959 |
| 960 std::vector<base::StringPiece> |
| 961 RenderFrameImpl::UniqueNameFrameAdapter::CollectAncestorNames( |
| 962 BeginPoint begin_point, |
| 963 bool (*should_stop)(base::StringPiece)) const { |
| 964 std::vector<base::StringPiece> result; |
| 965 for (blink::WebFrame* frame = begin_point == BeginPoint::kParentFrame |
| 966 ? GetWebFrame()->Parent() |
| 967 : GetWebFrame(); |
| 968 frame; frame = frame->Parent()) { |
| 969 result.push_back(UniqueNameForWebFrame(frame)); |
| 970 if (should_stop(result.back())) |
| 971 break; |
| 972 } |
| 973 return result; |
| 974 } |
| 975 |
| 976 std::vector<int> RenderFrameImpl::UniqueNameFrameAdapter::GetFramePosition( |
| 977 BeginPoint begin_point) const { |
| 978 std::vector<int> result; |
| 979 blink::WebFrame* parent = begin_point == BeginPoint::kParentFrame |
| 980 ? GetWebFrame()->Parent() |
| 981 : GetWebFrame(); |
| 982 blink::WebFrame* child = |
| 983 begin_point == BeginPoint::kParentFrame ? GetWebFrame() : nullptr; |
| 984 while (parent) { |
| 985 int position_in_parent = 0; |
| 986 blink::WebFrame* sibling = parent->FirstChild(); |
| 987 while (sibling != child) { |
| 988 sibling = sibling->NextSibling(); |
| 989 ++position_in_parent; |
| 990 } |
| 991 result.push_back(position_in_parent); |
| 992 |
| 993 child = parent; |
| 994 parent = parent->Parent(); |
| 995 } |
| 996 return result; |
| 997 } |
| 998 |
| 999 blink::WebLocalFrame* RenderFrameImpl::UniqueNameFrameAdapter::GetWebFrame() |
| 1000 const { |
| 1001 return render_frame_->frame_; |
| 1002 } |
| 1003 |
| 910 // static | 1004 // static |
| 911 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, | 1005 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, |
| 912 int32_t routing_id) { | 1006 int32_t routing_id) { |
| 913 DCHECK(routing_id != MSG_ROUTING_NONE); | 1007 DCHECK(routing_id != MSG_ROUTING_NONE); |
| 914 CreateParams params(render_view, routing_id); | 1008 CreateParams params(render_view, routing_id); |
| 915 | 1009 |
| 916 if (g_create_render_frame_impl) | 1010 if (g_create_render_frame_impl) |
| 917 return g_create_render_frame_impl(params); | 1011 return g_create_render_frame_impl(params); |
| 918 else | 1012 else |
| 919 return new RenderFrameImpl(params); | 1013 return new RenderFrameImpl(params); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1099 | 1193 |
| 1100 blink::WebURL RenderFrameImpl::OverrideFlashEmbedWithHTML( | 1194 blink::WebURL RenderFrameImpl::OverrideFlashEmbedWithHTML( |
| 1101 const blink::WebURL& url) { | 1195 const blink::WebURL& url) { |
| 1102 return GetContentClient()->renderer()->OverrideFlashEmbedWithHTML(url); | 1196 return GetContentClient()->renderer()->OverrideFlashEmbedWithHTML(url); |
| 1103 } | 1197 } |
| 1104 | 1198 |
| 1105 // RenderFrameImpl ---------------------------------------------------------- | 1199 // RenderFrameImpl ---------------------------------------------------------- |
| 1106 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 1200 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
| 1107 : frame_(NULL), | 1201 : frame_(NULL), |
| 1108 is_main_frame_(true), | 1202 is_main_frame_(true), |
| 1109 unique_name_helper_(this), | 1203 unique_name_frame_adapter_(this), |
| 1204 unique_name_helper_(&unique_name_frame_adapter_), |
| 1110 in_browser_initiated_detach_(false), | 1205 in_browser_initiated_detach_(false), |
| 1111 in_frame_tree_(false), | 1206 in_frame_tree_(false), |
| 1112 render_view_(params.render_view), | 1207 render_view_(params.render_view), |
| 1113 routing_id_(params.routing_id), | 1208 routing_id_(params.routing_id), |
| 1114 proxy_routing_id_(MSG_ROUTING_NONE), | 1209 proxy_routing_id_(MSG_ROUTING_NONE), |
| 1115 #if BUILDFLAG(ENABLE_PLUGINS) | 1210 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1116 plugin_power_saver_helper_(nullptr), | 1211 plugin_power_saver_helper_(nullptr), |
| 1117 plugin_find_handler_(nullptr), | 1212 plugin_find_handler_(nullptr), |
| 1118 #endif | 1213 #endif |
| 1119 cookie_jar_(this), | 1214 cookie_jar_(this), |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 3133 } | 3228 } |
| 3134 | 3229 |
| 3135 blink::WebLocalFrame* RenderFrameImpl::CreateChildFrame( | 3230 blink::WebLocalFrame* RenderFrameImpl::CreateChildFrame( |
| 3136 blink::WebLocalFrame* parent, | 3231 blink::WebLocalFrame* parent, |
| 3137 blink::WebTreeScopeType scope, | 3232 blink::WebTreeScopeType scope, |
| 3138 const blink::WebString& name, | 3233 const blink::WebString& name, |
| 3139 const blink::WebString& fallback_name, | 3234 const blink::WebString& fallback_name, |
| 3140 blink::WebSandboxFlags sandbox_flags, | 3235 blink::WebSandboxFlags sandbox_flags, |
| 3141 const blink::WebParsedFeaturePolicy& container_policy, | 3236 const blink::WebParsedFeaturePolicy& container_policy, |
| 3142 const blink::WebFrameOwnerProperties& frame_owner_properties) { | 3237 const blink::WebFrameOwnerProperties& frame_owner_properties) { |
| 3238 DCHECK_EQ(frame_, parent); |
| 3239 |
| 3143 // Synchronously notify the browser of a child frame creation to get the | 3240 // Synchronously notify the browser of a child frame creation to get the |
| 3144 // routing_id for the RenderFrame. | 3241 // routing_id for the RenderFrame. |
| 3145 int child_routing_id = MSG_ROUTING_NONE; | 3242 int child_routing_id = MSG_ROUTING_NONE; |
| 3146 FrameHostMsg_CreateChildFrame_Params params; | 3243 FrameHostMsg_CreateChildFrame_Params params; |
| 3147 params.parent_routing_id = routing_id_; | 3244 params.parent_routing_id = routing_id_; |
| 3148 params.scope = scope; | 3245 params.scope = scope; |
| 3149 params.frame_name = name.Utf8(); | 3246 params.frame_name = name.Utf8(); |
| 3150 // The unique name generation logic was moved out of Blink, so for historical | 3247 // The unique name generation logic was moved out of Blink, so for historical |
| 3151 // reasons, unique name generation needs to take something called the | 3248 // reasons, unique name generation needs to take something called the |
| 3152 // |fallback_name| into account. Normally, unique names are generated based on | 3249 // |fallback_name| into account. Normally, unique names are generated based on |
| 3153 // the browing context name. For new frames, the initial browsing context name | 3250 // the browing context name. For new frames, the initial browsing context name |
| 3154 // comes from the name attribute of the browsing context container element. | 3251 // comes from the name attribute of the browsing context container element. |
| 3155 // | 3252 // |
| 3156 // However, when the browsing context name is null, Blink instead uses the | 3253 // However, when the browsing context name is null, Blink instead uses the |
| 3157 // "fallback name" to derive the unique name. The exact contents of the | 3254 // "fallback name" to derive the unique name. The exact contents of the |
| 3158 // "fallback name" are unspecified, but may contain the value of the | 3255 // "fallback name" are unspecified, but may contain the value of the |
| 3159 // 'subresource attribute' of the browsing context container element. | 3256 // 'subresource attribute' of the browsing context container element. |
| 3160 // | 3257 // |
| 3161 // Note that Blink can't be changed to just pass |fallback_name| as |name| in | 3258 // Note that Blink can't be changed to just pass |fallback_name| as |name| in |
| 3162 // the case |name| is empty: |fallback_name| should never affect the actual | 3259 // the case |name| is empty: |fallback_name| should never affect the actual |
| 3163 // browsing context name, only unique name generation. | 3260 // browsing context name, only unique name generation. |
| 3164 params.frame_unique_name = UniqueNameHelper::GenerateNameForNewChildFrame( | 3261 params.frame_unique_name = unique_name_helper_.GenerateNameForNewChildFrame( |
| 3165 parent, | |
| 3166 params.frame_name.empty() ? fallback_name.Utf8() : params.frame_name); | 3262 params.frame_name.empty() ? fallback_name.Utf8() : params.frame_name); |
| 3167 params.sandbox_flags = sandbox_flags; | 3263 params.sandbox_flags = sandbox_flags; |
| 3168 params.container_policy = FeaturePolicyHeaderFromWeb(container_policy); | 3264 params.container_policy = FeaturePolicyHeaderFromWeb(container_policy); |
| 3169 params.frame_owner_properties = | 3265 params.frame_owner_properties = |
| 3170 ConvertWebFrameOwnerPropertiesToFrameOwnerProperties( | 3266 ConvertWebFrameOwnerPropertiesToFrameOwnerProperties( |
| 3171 frame_owner_properties); | 3267 frame_owner_properties); |
| 3172 Send(new FrameHostMsg_CreateChildFrame(params, &child_routing_id)); | 3268 Send(new FrameHostMsg_CreateChildFrame(params, &child_routing_id)); |
| 3173 | 3269 |
| 3174 // Allocation of routing id failed, so we can't create a child frame. This can | 3270 // Allocation of routing id failed, so we can't create a child frame. This can |
| 3175 // happen if the synchronous IPC message above has failed. This can | 3271 // happen if the synchronous IPC message above has failed. This can |
| (...skipping 3898 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 7074 policy(info.default_policy), | 7170 policy(info.default_policy), |
| 7075 replaces_current_history_item(info.replaces_current_history_item), | 7171 replaces_current_history_item(info.replaces_current_history_item), |
| 7076 history_navigation_in_new_child_frame( | 7172 history_navigation_in_new_child_frame( |
| 7077 info.is_history_navigation_in_new_child_frame), | 7173 info.is_history_navigation_in_new_child_frame), |
| 7078 client_redirect(info.is_client_redirect), | 7174 client_redirect(info.is_client_redirect), |
| 7079 cache_disabled(info.is_cache_disabled), | 7175 cache_disabled(info.is_cache_disabled), |
| 7080 form(info.form), | 7176 form(info.form), |
| 7081 source_location(info.source_location) {} | 7177 source_location(info.source_location) {} |
| 7082 | 7178 |
| 7083 } // namespace content | 7179 } // namespace content |
| OLD | NEW |