Chromium Code Reviews| 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 <algorithm> | |
| 7 #include <map> | 8 #include <map> |
| 8 #include <string> | 9 #include <string> |
| 9 #include <utility> | 10 #include <utility> |
| 10 #include <vector> | 11 #include <vector> |
| 11 | 12 |
| 12 #include "base/auto_reset.h" | 13 #include "base/auto_reset.h" |
| 13 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
| 14 #include "base/command_line.h" | 15 #include "base/command_line.h" |
| 15 #include "base/debug/alias.h" | 16 #include "base/debug/alias.h" |
| 16 #include "base/debug/asan_invalid_access.h" | 17 #include "base/debug/asan_invalid_access.h" |
| (...skipping 883 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 900 } | 901 } |
| 901 | 902 |
| 902 struct RenderFrameImpl::PendingFileChooser { | 903 struct RenderFrameImpl::PendingFileChooser { |
| 903 PendingFileChooser(const FileChooserParams& p, | 904 PendingFileChooser(const FileChooserParams& p, |
| 904 blink::WebFileChooserCompletion* c) | 905 blink::WebFileChooserCompletion* c) |
| 905 : params(p), completion(c) {} | 906 : params(p), completion(c) {} |
| 906 FileChooserParams params; | 907 FileChooserParams params; |
| 907 blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. | 908 blink::WebFileChooserCompletion* completion; // MAY BE NULL to skip callback. |
| 908 }; | 909 }; |
| 909 | 910 |
| 911 const std::string& UniqueNameForWebFrame(blink::WebFrame* frame) { | |
| 912 return frame->IsWebLocalFrame() | |
| 913 ? RenderFrameImpl::FromWebFrame(frame)->unique_name() | |
| 914 : RenderFrameProxy::FromWebFrame(frame)->unique_name(); | |
| 915 } | |
| 916 | |
| 917 RenderFrameImpl::RenderFrameAdapter::RenderFrameAdapter( | |
| 918 RenderFrameImpl* render_frame) | |
| 919 : render_frame_(render_frame) {} | |
| 920 | |
| 921 RenderFrameImpl::RenderFrameAdapter::~RenderFrameAdapter() {} | |
| 922 | |
| 923 bool RenderFrameImpl::RenderFrameAdapter::IsMainFrame() const { | |
| 924 return render_frame_->IsMainFrame(); | |
| 925 } | |
| 926 | |
| 927 bool RenderFrameImpl::RenderFrameAdapter::IsCandidateUnique( | |
| 928 const std::string& name) const { | |
| 929 // This method is currently O(N), where N = number of frames in the tree. | |
| 930 DCHECK(!name.empty()); | |
| 931 | |
| 932 for (blink::WebFrame* frame = GetWebFrame()->Top(); frame; | |
| 933 frame = frame->TraverseNext()) { | |
| 934 if (frame == GetWebFrame()) | |
|
Łukasz Anforowicz
2017/05/25 16:48:50
I wonder if this check means that we can avoid the
dcheng
2017/05/25 18:25:03
This doesn't work very well as it turns out: since
Łukasz Anforowicz
2017/05/25 18:33:18
Acknowledged.
| |
| 935 continue; | |
| 936 if (UniqueNameForWebFrame(frame) == name) | |
| 937 return false; | |
| 938 } | |
| 939 | |
| 940 return true; | |
| 941 } | |
| 942 | |
| 943 int RenderFrameImpl::RenderFrameAdapter::GetSiblingCount() const { | |
| 944 int sibling_count = 0; | |
| 945 for (blink::WebFrame* frame = GetWebFrame()->Parent()->FirstChild(); frame; | |
| 946 frame = frame->NextSibling()) { | |
| 947 if (frame == GetWebFrame()) | |
| 948 continue; | |
| 949 ++sibling_count; | |
| 950 } | |
| 951 return sibling_count; | |
| 952 } | |
| 953 | |
| 954 int RenderFrameImpl::RenderFrameAdapter::GetChildCount() const { | |
| 955 int child_count = 0; | |
| 956 for (blink::WebFrame* frame = GetWebFrame()->FirstChild(); frame; | |
| 957 frame = frame->NextSibling()) { | |
| 958 ++child_count; | |
| 959 } | |
| 960 return child_count; | |
| 961 } | |
| 962 | |
| 963 std::vector<base::StringPiece> | |
| 964 RenderFrameImpl::RenderFrameAdapter::CollectAncestorNames( | |
| 965 BeginPoint begin_point, | |
| 966 bool (*should_stop)(base::StringPiece)) const { | |
| 967 std::vector<base::StringPiece> result; | |
| 968 for (blink::WebFrame* frame = begin_point == BeginPoint::kParentFrame | |
| 969 ? GetWebFrame()->Parent() | |
| 970 : GetWebFrame(); | |
| 971 frame; frame = frame->Parent()) { | |
| 972 result.push_back(UniqueNameForWebFrame(frame)); | |
| 973 if (should_stop(result.back())) | |
| 974 break; | |
| 975 } | |
| 976 // Reverse, as the names should be ordered from root to leaf. Contrast with | |
| 977 // GetFramePosition(), which has the opposite ordering requirement… | |
| 978 std::reverse(result.begin(), result.end()); | |
|
Łukasz Anforowicz
2017/05/25 16:48:50
Will the other implementation (for exploded page s
dcheng
2017/05/25 18:25:03
I was going to do this in the followup, but doing
| |
| 979 return result; | |
| 980 } | |
| 981 | |
| 982 std::vector<int> RenderFrameImpl::RenderFrameAdapter::GetFramePosition( | |
| 983 BeginPoint begin_point) const { | |
| 984 std::vector<int> result; | |
| 985 blink::WebFrame* parent = begin_point == BeginPoint::kParentFrame | |
| 986 ? GetWebFrame()->Parent() | |
| 987 : GetWebFrame(); | |
| 988 blink::WebFrame* child = | |
| 989 begin_point == BeginPoint::kParentFrame ? GetWebFrame() : nullptr; | |
| 990 while (parent) { | |
| 991 int position_in_parent = 0; | |
| 992 blink::WebFrame* sibling = parent->FirstChild(); | |
| 993 while (sibling != child) { | |
| 994 sibling = sibling->NextSibling(); | |
| 995 ++position_in_parent; | |
| 996 } | |
| 997 result.push_back(position_in_parent); | |
| 998 | |
| 999 child = parent; | |
| 1000 parent = parent->Parent(); | |
| 1001 } | |
| 1002 return result; | |
| 1003 } | |
| 1004 | |
| 1005 blink::WebLocalFrame* RenderFrameImpl::RenderFrameAdapter::GetWebFrame() const { | |
| 1006 return render_frame_->frame_; | |
| 1007 } | |
| 1008 | |
| 910 // static | 1009 // static |
| 911 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, | 1010 RenderFrameImpl* RenderFrameImpl::Create(RenderViewImpl* render_view, |
| 912 int32_t routing_id) { | 1011 int32_t routing_id) { |
| 913 DCHECK(routing_id != MSG_ROUTING_NONE); | 1012 DCHECK(routing_id != MSG_ROUTING_NONE); |
| 914 CreateParams params(render_view, routing_id); | 1013 CreateParams params(render_view, routing_id); |
| 915 | 1014 |
| 916 if (g_create_render_frame_impl) | 1015 if (g_create_render_frame_impl) |
| 917 return g_create_render_frame_impl(params); | 1016 return g_create_render_frame_impl(params); |
| 918 else | 1017 else |
| 919 return new RenderFrameImpl(params); | 1018 return new RenderFrameImpl(params); |
| (...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1099 | 1198 |
| 1100 blink::WebURL RenderFrameImpl::OverrideFlashEmbedWithHTML( | 1199 blink::WebURL RenderFrameImpl::OverrideFlashEmbedWithHTML( |
| 1101 const blink::WebURL& url) { | 1200 const blink::WebURL& url) { |
| 1102 return GetContentClient()->renderer()->OverrideFlashEmbedWithHTML(url); | 1201 return GetContentClient()->renderer()->OverrideFlashEmbedWithHTML(url); |
| 1103 } | 1202 } |
| 1104 | 1203 |
| 1105 // RenderFrameImpl ---------------------------------------------------------- | 1204 // RenderFrameImpl ---------------------------------------------------------- |
| 1106 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) | 1205 RenderFrameImpl::RenderFrameImpl(const CreateParams& params) |
| 1107 : frame_(NULL), | 1206 : frame_(NULL), |
| 1108 is_main_frame_(true), | 1207 is_main_frame_(true), |
| 1109 unique_name_helper_(this), | 1208 render_frame_adapter_(this), |
| 1209 unique_name_helper_(&render_frame_adapter_), | |
| 1110 in_browser_initiated_detach_(false), | 1210 in_browser_initiated_detach_(false), |
| 1111 in_frame_tree_(false), | 1211 in_frame_tree_(false), |
| 1112 render_view_(params.render_view), | 1212 render_view_(params.render_view), |
| 1113 routing_id_(params.routing_id), | 1213 routing_id_(params.routing_id), |
| 1114 proxy_routing_id_(MSG_ROUTING_NONE), | 1214 proxy_routing_id_(MSG_ROUTING_NONE), |
| 1115 #if BUILDFLAG(ENABLE_PLUGINS) | 1215 #if BUILDFLAG(ENABLE_PLUGINS) |
| 1116 plugin_power_saver_helper_(nullptr), | 1216 plugin_power_saver_helper_(nullptr), |
| 1117 plugin_find_handler_(nullptr), | 1217 plugin_find_handler_(nullptr), |
| 1118 #endif | 1218 #endif |
| 1119 cookie_jar_(this), | 1219 cookie_jar_(this), |
| (...skipping 2013 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3133 } | 3233 } |
| 3134 | 3234 |
| 3135 blink::WebLocalFrame* RenderFrameImpl::CreateChildFrame( | 3235 blink::WebLocalFrame* RenderFrameImpl::CreateChildFrame( |
| 3136 blink::WebLocalFrame* parent, | 3236 blink::WebLocalFrame* parent, |
| 3137 blink::WebTreeScopeType scope, | 3237 blink::WebTreeScopeType scope, |
| 3138 const blink::WebString& name, | 3238 const blink::WebString& name, |
| 3139 const blink::WebString& fallback_name, | 3239 const blink::WebString& fallback_name, |
| 3140 blink::WebSandboxFlags sandbox_flags, | 3240 blink::WebSandboxFlags sandbox_flags, |
| 3141 const blink::WebParsedFeaturePolicy& container_policy, | 3241 const blink::WebParsedFeaturePolicy& container_policy, |
| 3142 const blink::WebFrameOwnerProperties& frame_owner_properties) { | 3242 const blink::WebFrameOwnerProperties& frame_owner_properties) { |
| 3243 DCHECK_EQ(frame_, parent); | |
|
Łukasz Anforowicz
2017/05/25 16:48:50
Does that mean that the |parent| parameter can be
dcheng
2017/05/25 18:25:03
Likely. But out of scope of this patch.
| |
| 3244 | |
| 3143 // Synchronously notify the browser of a child frame creation to get the | 3245 // Synchronously notify the browser of a child frame creation to get the |
| 3144 // routing_id for the RenderFrame. | 3246 // routing_id for the RenderFrame. |
| 3145 int child_routing_id = MSG_ROUTING_NONE; | 3247 int child_routing_id = MSG_ROUTING_NONE; |
| 3146 FrameHostMsg_CreateChildFrame_Params params; | 3248 FrameHostMsg_CreateChildFrame_Params params; |
| 3147 params.parent_routing_id = routing_id_; | 3249 params.parent_routing_id = routing_id_; |
| 3148 params.scope = scope; | 3250 params.scope = scope; |
| 3149 params.frame_name = name.Utf8(); | 3251 params.frame_name = name.Utf8(); |
| 3150 // The unique name generation logic was moved out of Blink, so for historical | 3252 // The unique name generation logic was moved out of Blink, so for historical |
| 3151 // reasons, unique name generation needs to take something called the | 3253 // reasons, unique name generation needs to take something called the |
| 3152 // |fallback_name| into account. Normally, unique names are generated based on | 3254 // |fallback_name| into account. Normally, unique names are generated based on |
| 3153 // the browing context name. For new frames, the initial browsing context name | 3255 // the browing context name. For new frames, the initial browsing context name |
| 3154 // comes from the name attribute of the browsing context container element. | 3256 // comes from the name attribute of the browsing context container element. |
| 3155 // | 3257 // |
| 3156 // However, when the browsing context name is null, Blink instead uses the | 3258 // 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 | 3259 // "fallback name" to derive the unique name. The exact contents of the |
| 3158 // "fallback name" are unspecified, but may contain the value of the | 3260 // "fallback name" are unspecified, but may contain the value of the |
| 3159 // 'subresource attribute' of the browsing context container element. | 3261 // 'subresource attribute' of the browsing context container element. |
| 3160 // | 3262 // |
| 3161 // Note that Blink can't be changed to just pass |fallback_name| as |name| in | 3263 // 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 | 3264 // the case |name| is empty: |fallback_name| should never affect the actual |
| 3163 // browsing context name, only unique name generation. | 3265 // browsing context name, only unique name generation. |
| 3164 params.frame_unique_name = UniqueNameHelper::GenerateNameForNewChildFrame( | 3266 params.frame_unique_name = unique_name_helper_.GenerateNameForNewChildFrame( |
| 3165 parent, | |
| 3166 params.frame_name.empty() ? fallback_name.Utf8() : params.frame_name); | 3267 params.frame_name.empty() ? fallback_name.Utf8() : params.frame_name); |
| 3167 params.sandbox_flags = sandbox_flags; | 3268 params.sandbox_flags = sandbox_flags; |
| 3168 params.container_policy = FeaturePolicyHeaderFromWeb(container_policy); | 3269 params.container_policy = FeaturePolicyHeaderFromWeb(container_policy); |
| 3169 params.frame_owner_properties = | 3270 params.frame_owner_properties = |
| 3170 ConvertWebFrameOwnerPropertiesToFrameOwnerProperties( | 3271 ConvertWebFrameOwnerPropertiesToFrameOwnerProperties( |
| 3171 frame_owner_properties); | 3272 frame_owner_properties); |
| 3172 Send(new FrameHostMsg_CreateChildFrame(params, &child_routing_id)); | 3273 Send(new FrameHostMsg_CreateChildFrame(params, &child_routing_id)); |
| 3173 | 3274 |
| 3174 // Allocation of routing id failed, so we can't create a child frame. This can | 3275 // 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 | 3276 // 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), | 7175 policy(info.default_policy), |
| 7075 replaces_current_history_item(info.replaces_current_history_item), | 7176 replaces_current_history_item(info.replaces_current_history_item), |
| 7076 history_navigation_in_new_child_frame( | 7177 history_navigation_in_new_child_frame( |
| 7077 info.is_history_navigation_in_new_child_frame), | 7178 info.is_history_navigation_in_new_child_frame), |
| 7078 client_redirect(info.is_client_redirect), | 7179 client_redirect(info.is_client_redirect), |
| 7079 cache_disabled(info.is_cache_disabled), | 7180 cache_disabled(info.is_cache_disabled), |
| 7080 form(info.form), | 7181 form(info.form), |
| 7081 source_location(info.source_location) {} | 7182 source_location(info.source_location) {} |
| 7082 | 7183 |
| 7083 } // namespace content | 7184 } // namespace content |
| OLD | NEW |