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

Side by Side Diff: third_party/WebKit/Source/web/WebLocalFrameImpl.cpp

Issue 2888203006: Move the logic to retrieve the WebPluginContainer to LocalFrame and Node. (Closed)
Patch Set: Rename & format. Created 3 years, 7 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
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2009 Google Inc. All rights reserved. 2 * Copyright (C) 2009 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after
239 static int g_frame_count = 0; 239 static int g_frame_count = 0;
240 240
241 static HeapVector<ScriptSourceCode> CreateSourcesVector( 241 static HeapVector<ScriptSourceCode> CreateSourcesVector(
242 const WebScriptSource* sources_in, 242 const WebScriptSource* sources_in,
243 unsigned num_sources) { 243 unsigned num_sources) {
244 HeapVector<ScriptSourceCode> sources; 244 HeapVector<ScriptSourceCode> sources;
245 sources.Append(sources_in, num_sources); 245 sources.Append(sources_in, num_sources);
246 return sources; 246 return sources;
247 } 247 }
248 248
249 WebPluginContainerBase* WebLocalFrameImpl::PluginContainerFromFrame(
250 LocalFrame* frame) {
251 if (!frame)
252 return 0;
253 if (!frame->GetDocument() || !frame->GetDocument()->IsPluginDocument())
254 return 0;
255 PluginDocument* plugin_document = ToPluginDocument(frame->GetDocument());
256 return ToWebPluginContainerBase(plugin_document->GetPluginView());
257 }
258
259 WebPluginContainerBase* WebLocalFrameImpl::CurrentPluginContainer(
260 LocalFrame* frame,
261 Node* node) {
262 WebPluginContainerBase* plugin_container = PluginContainerFromFrame(frame);
263 if (plugin_container)
264 return plugin_container;
265
266 if (!node) {
267 DCHECK(frame->GetDocument());
268 node = frame->GetDocument()->FocusedElement();
269 }
270 return ToWebPluginContainerBase(WebNode::PluginContainerFromNode(node));
271 }
272
273 // Simple class to override some of PrintContext behavior. Some of the methods 249 // Simple class to override some of PrintContext behavior. Some of the methods
274 // made virtual so that they can be overridden by ChromePluginPrintContext. 250 // made virtual so that they can be overridden by ChromePluginPrintContext.
275 class ChromePrintContext : public PrintContext { 251 class ChromePrintContext : public PrintContext {
276 WTF_MAKE_NONCOPYABLE(ChromePrintContext); 252 WTF_MAKE_NONCOPYABLE(ChromePrintContext);
277 253
278 public: 254 public:
279 explicit ChromePrintContext(LocalFrame* frame) 255 explicit ChromePrintContext(LocalFrame* frame)
280 : PrintContext(frame), printed_page_width_(0) {} 256 : PrintContext(frame), printed_page_width_(0) {}
281 257
282 ~ChromePrintContext() override {} 258 ~ChromePrintContext() override {}
(...skipping 810 matching lines...) Expand 10 before | Expand all | Expand 10 after
1093 } 1069 }
1094 1070
1095 bool WebLocalFrameImpl::IsSpellCheckingEnabled() const { 1071 bool WebLocalFrameImpl::IsSpellCheckingEnabled() const {
1096 return GetFrame()->GetSpellChecker().IsSpellCheckingEnabled(); 1072 return GetFrame()->GetSpellChecker().IsSpellCheckingEnabled();
1097 } 1073 }
1098 1074
1099 void WebLocalFrameImpl::ReplaceMisspelledRange(const WebString& text) { 1075 void WebLocalFrameImpl::ReplaceMisspelledRange(const WebString& text) {
1100 // If this caret selection has two or more markers, this function replace the 1076 // If this caret selection has two or more markers, this function replace the
1101 // range covered by the first marker with the specified word as Microsoft Word 1077 // range covered by the first marker with the specified word as Microsoft Word
1102 // does. 1078 // does.
1103 if (PluginContainerFromFrame(GetFrame())) 1079 if (CurrentPluginContainer(GetFrame()))
1104 return; 1080 return;
1105 1081
1106 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1082 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1107 // needs to be audited. see http://crbug.com/590369 for more details. 1083 // needs to be audited. see http://crbug.com/590369 for more details.
1108 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1084 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1109 1085
1110 GetFrame()->GetSpellChecker().ReplaceMisspelledRange(text); 1086 GetFrame()->GetSpellChecker().ReplaceMisspelledRange(text);
1111 } 1087 }
1112 1088
1113 void WebLocalFrameImpl::RemoveSpellingMarkers() { 1089 void WebLocalFrameImpl::RemoveSpellingMarkers() {
1114 GetFrame()->GetSpellChecker().RemoveSpellingMarkers(); 1090 GetFrame()->GetSpellChecker().RemoveSpellingMarkers();
1115 } 1091 }
1116 1092
1117 void WebLocalFrameImpl::RemoveSpellingMarkersUnderWords( 1093 void WebLocalFrameImpl::RemoveSpellingMarkersUnderWords(
1118 const WebVector<WebString>& words) { 1094 const WebVector<WebString>& words) {
1119 Vector<String> converted_words; 1095 Vector<String> converted_words;
1120 converted_words.Append(words.Data(), words.size()); 1096 converted_words.Append(words.Data(), words.size());
1121 GetFrame()->RemoveSpellingMarkersUnderWords(converted_words); 1097 GetFrame()->RemoveSpellingMarkersUnderWords(converted_words);
1122 } 1098 }
1123 1099
1124 bool WebLocalFrameImpl::HasSelection() const { 1100 bool WebLocalFrameImpl::HasSelection() const {
1125 WebPluginContainerBase* plugin_container = 1101 WebPluginContainerBase* plugin_container = CurrentPluginContainer(GetFrame());
1126 PluginContainerFromFrame(GetFrame());
1127 if (plugin_container) 1102 if (plugin_container)
1128 return plugin_container->Plugin()->HasSelection(); 1103 return plugin_container->Plugin()->HasSelection();
1129 1104
1130 // frame()->selection()->isNone() never returns true. 1105 // frame()->selection()->isNone() never returns true.
1131 return GetFrame() 1106 return GetFrame()
1132 ->Selection() 1107 ->Selection()
1133 .ComputeVisibleSelectionInDOMTreeDeprecated() 1108 .ComputeVisibleSelectionInDOMTreeDeprecated()
1134 .Start() != GetFrame() 1109 .Start() != GetFrame()
1135 ->Selection() 1110 ->Selection()
1136 .ComputeVisibleSelectionInDOMTreeDeprecated() 1111 .ComputeVisibleSelectionInDOMTreeDeprecated()
1137 .end(); 1112 .end();
1138 } 1113 }
1139 1114
1140 WebRange WebLocalFrameImpl::SelectionRange() const { 1115 WebRange WebLocalFrameImpl::SelectionRange() const {
1141 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1116 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1142 // needs to be audited. See http://crbug.com/590369 for more details. 1117 // needs to be audited. See http://crbug.com/590369 for more details.
1143 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1118 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1144 1119
1145 return GetFrame() 1120 return GetFrame()
1146 ->Selection() 1121 ->Selection()
1147 .ComputeVisibleSelectionInDOMTreeDeprecated() 1122 .ComputeVisibleSelectionInDOMTreeDeprecated()
1148 .ToNormalizedEphemeralRange(); 1123 .ToNormalizedEphemeralRange();
1149 } 1124 }
1150 1125
1151 WebString WebLocalFrameImpl::SelectionAsText() const { 1126 WebString WebLocalFrameImpl::SelectionAsText() const {
1152 WebPluginContainerBase* plugin_container = 1127 WebPluginContainerBase* plugin_container = CurrentPluginContainer(GetFrame());
1153 PluginContainerFromFrame(GetFrame());
1154 if (plugin_container) 1128 if (plugin_container)
1155 return plugin_container->Plugin()->SelectionAsText(); 1129 return plugin_container->Plugin()->SelectionAsText();
1156 1130
1157 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1131 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1158 // needs to be audited. See http://crbug.com/590369 for more details. 1132 // needs to be audited. See http://crbug.com/590369 for more details.
1159 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1133 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1160 1134
1161 String text = GetFrame()->Selection().SelectedText( 1135 String text = GetFrame()->Selection().SelectedText(
1162 TextIteratorBehavior::EmitsObjectReplacementCharacterBehavior()); 1136 TextIteratorBehavior::EmitsObjectReplacementCharacterBehavior());
1163 #if OS(WIN) 1137 #if OS(WIN)
1164 ReplaceNewlinesWithWindowsStyleNewlines(text); 1138 ReplaceNewlinesWithWindowsStyleNewlines(text);
1165 #endif 1139 #endif
1166 ReplaceNBSPWithSpace(text); 1140 ReplaceNBSPWithSpace(text);
1167 return text; 1141 return text;
1168 } 1142 }
1169 1143
1170 WebString WebLocalFrameImpl::SelectionAsMarkup() const { 1144 WebString WebLocalFrameImpl::SelectionAsMarkup() const {
1171 WebPluginContainerBase* plugin_container = 1145 WebPluginContainerBase* plugin_container = CurrentPluginContainer(GetFrame());
1172 PluginContainerFromFrame(GetFrame());
1173 if (plugin_container) 1146 if (plugin_container)
1174 return plugin_container->Plugin()->SelectionAsMarkup(); 1147 return plugin_container->Plugin()->SelectionAsMarkup();
1175 1148
1176 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets 1149 // TODO(editing-dev): The use of updateStyleAndLayoutIgnorePendingStylesheets
1177 // needs to be audited. See http://crbug.com/590369 for more details. 1150 // needs to be audited. See http://crbug.com/590369 for more details.
1178 // Selection normalization and markup generation require clean layout. 1151 // Selection normalization and markup generation require clean layout.
1179 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets(); 1152 GetFrame()->GetDocument()->UpdateStyleAndLayoutIgnorePendingStylesheets();
1180 1153
1181 return GetFrame()->Selection().SelectedHTMLForClipboard(); 1154 return GetFrame()->Selection().SelectedHTMLForClipboard();
1182 } 1155 }
(...skipping 191 matching lines...) Expand 10 before | Expand all | Expand 10 after
1374 GetFrame()->Selection().SetCaretVisible(visible); 1347 GetFrame()->Selection().SetCaretVisible(visible);
1375 } 1348 }
1376 1349
1377 VisiblePosition WebLocalFrameImpl::VisiblePositionForViewportPoint( 1350 VisiblePosition WebLocalFrameImpl::VisiblePositionForViewportPoint(
1378 const WebPoint& point_in_viewport) { 1351 const WebPoint& point_in_viewport) {
1379 return VisiblePositionForContentsPoint( 1352 return VisiblePositionForContentsPoint(
1380 GetFrame()->View()->ViewportToContents(point_in_viewport), GetFrame()); 1353 GetFrame()->View()->ViewportToContents(point_in_viewport), GetFrame());
1381 } 1354 }
1382 1355
1383 WebPlugin* WebLocalFrameImpl::FocusedPluginIfInputMethodSupported() { 1356 WebPlugin* WebLocalFrameImpl::FocusedPluginIfInputMethodSupported() {
1384 WebPluginContainerBase* container = 1357 WebPluginContainerBase* container = CurrentPluginContainer(GetFrame());
1385 WebLocalFrameImpl::CurrentPluginContainer(GetFrame());
1386 if (container && container->SupportsInputMethod()) 1358 if (container && container->SupportsInputMethod())
1387 return container->Plugin(); 1359 return container->Plugin();
1388 return 0; 1360 return 0;
1389 } 1361 }
1390 1362
1391 int WebLocalFrameImpl::PrintBegin(const WebPrintParams& print_params, 1363 int WebLocalFrameImpl::PrintBegin(const WebPrintParams& print_params,
1392 const WebNode& constrain_to_node) { 1364 const WebNode& constrain_to_node) {
1393 DCHECK(!GetFrame()->GetDocument()->IsFrameSet()); 1365 DCHECK(!GetFrame()->GetDocument()->IsFrameSet());
1394 WebPluginContainerBase* plugin_container = nullptr; 1366 WebPluginContainerBase* plugin_container = nullptr;
1395 if (constrain_to_node.IsNull()) { 1367 if (constrain_to_node.IsNull()) {
1396 // If this is a plugin document, check if the plugin supports its own 1368 // If this is a plugin document, check if the plugin supports its own
1397 // printing. If it does, we will delegate all printing to that. 1369 // printing. If it does, we will delegate all printing to that.
1398 plugin_container = PluginContainerFromFrame(GetFrame()); 1370 plugin_container = CurrentPluginContainer(GetFrame());
1399 } else { 1371 } else {
1400 // We only support printing plugin nodes for now. 1372 // We only support printing plugin nodes for now.
1401 plugin_container = 1373 plugin_container =
1402 ToWebPluginContainerBase(constrain_to_node.PluginContainer()); 1374 ToWebPluginContainerBase(constrain_to_node.PluginContainer());
1403 } 1375 }
1404 1376
1405 if (plugin_container && plugin_container->SupportsPaginatedPrint()) { 1377 if (plugin_container && plugin_container->SupportsPaginatedPrint()) {
1406 print_context_ = new ChromePluginPrintContext(GetFrame(), plugin_container, 1378 print_context_ = new ChromePluginPrintContext(GetFrame(), plugin_container,
1407 print_params); 1379 print_params);
1408 } else { 1380 } else {
(...skipping 25 matching lines...) Expand all
1434 } 1406 }
1435 1407
1436 void WebLocalFrameImpl::PrintEnd() { 1408 void WebLocalFrameImpl::PrintEnd() {
1437 DCHECK(print_context_); 1409 DCHECK(print_context_);
1438 print_context_->EndPrintMode(); 1410 print_context_->EndPrintMode();
1439 print_context_.Clear(); 1411 print_context_.Clear();
1440 } 1412 }
1441 1413
1442 bool WebLocalFrameImpl::IsPrintScalingDisabledForPlugin(const WebNode& node) { 1414 bool WebLocalFrameImpl::IsPrintScalingDisabledForPlugin(const WebNode& node) {
1443 WebPluginContainerBase* plugin_container = 1415 WebPluginContainerBase* plugin_container =
1444 node.IsNull() ? PluginContainerFromFrame(GetFrame()) 1416 node.IsNull() ? CurrentPluginContainer(GetFrame())
1445 : ToWebPluginContainerBase(node.PluginContainer()); 1417 : ToWebPluginContainerBase(node.PluginContainer());
1446 1418
1447 if (!plugin_container || !plugin_container->SupportsPaginatedPrint()) 1419 if (!plugin_container || !plugin_container->SupportsPaginatedPrint())
1448 return false; 1420 return false;
1449 1421
1450 return plugin_container->IsPrintScalingDisabled(); 1422 return plugin_container->IsPrintScalingDisabled();
1451 } 1423 }
1452 1424
1453 bool WebLocalFrameImpl::GetPrintPresetOptionsForPlugin( 1425 bool WebLocalFrameImpl::GetPrintPresetOptionsForPlugin(
1454 const WebNode& node, 1426 const WebNode& node,
1455 WebPrintPresetOptions* preset_options) { 1427 WebPrintPresetOptions* preset_options) {
1456 WebPluginContainerBase* plugin_container = 1428 WebPluginContainerBase* plugin_container =
1457 node.IsNull() ? PluginContainerFromFrame(GetFrame()) 1429 node.IsNull() ? CurrentPluginContainer(GetFrame())
1458 : ToWebPluginContainerBase(node.PluginContainer()); 1430 : ToWebPluginContainerBase(node.PluginContainer());
1459 1431
1460 if (!plugin_container || !plugin_container->SupportsPaginatedPrint()) 1432 if (!plugin_container || !plugin_container->SupportsPaginatedPrint())
1461 return false; 1433 return false;
1462 1434
1463 return plugin_container->GetPrintPresetOptionsFromDocument(preset_options); 1435 return plugin_container->GetPrintPresetOptionsFromDocument(preset_options);
1464 } 1436 }
1465 1437
1466 bool WebLocalFrameImpl::HasCustomPageSizeStyle(int page_index) { 1438 bool WebLocalFrameImpl::HasCustomPageSizeStyle(int page_index) {
1467 return GetFrame() 1439 return GetFrame()
(...skipping 440 matching lines...) Expand 10 before | Expand all | Expand 10 after
1908 1880
1909 void WebLocalFrameImpl::DidFail(const ResourceError& error, 1881 void WebLocalFrameImpl::DidFail(const ResourceError& error,
1910 bool was_provisional, 1882 bool was_provisional,
1911 HistoryCommitType commit_type) { 1883 HistoryCommitType commit_type) {
1912 if (!Client()) 1884 if (!Client())
1913 return; 1885 return;
1914 WebURLError web_error = error; 1886 WebURLError web_error = error;
1915 WebHistoryCommitType web_commit_type = 1887 WebHistoryCommitType web_commit_type =
1916 static_cast<WebHistoryCommitType>(commit_type); 1888 static_cast<WebHistoryCommitType>(commit_type);
1917 1889
1918 if (WebPluginContainerBase* plugin = PluginContainerFromFrame(GetFrame())) 1890 if (WebPluginContainerBase* plugin = CurrentPluginContainer(GetFrame()))
1919 plugin->DidFailLoading(error); 1891 plugin->DidFailLoading(error);
1920 1892
1921 if (was_provisional) 1893 if (was_provisional)
1922 Client()->DidFailProvisionalLoad(web_error, web_commit_type); 1894 Client()->DidFailProvisionalLoad(web_error, web_commit_type);
1923 else 1895 else
1924 Client()->DidFailLoad(web_error, web_commit_type); 1896 Client()->DidFailLoad(web_error, web_commit_type);
1925 } 1897 }
1926 1898
1927 void WebLocalFrameImpl::DidFinish() { 1899 void WebLocalFrameImpl::DidFinish() {
1928 if (!Client()) 1900 if (!Client())
1929 return; 1901 return;
1930 1902
1931 if (WebPluginContainerBase* plugin = PluginContainerFromFrame(GetFrame())) 1903 if (WebPluginContainerBase* plugin = CurrentPluginContainer(GetFrame()))
1932 plugin->DidFinishLoading(); 1904 plugin->DidFinishLoading();
1933 1905
1934 Client()->DidFinishLoad(); 1906 Client()->DidFinishLoad();
1935 } 1907 }
1936 1908
1937 void WebLocalFrameImpl::SetCanHaveScrollbars(bool can_have_scrollbars) { 1909 void WebLocalFrameImpl::SetCanHaveScrollbars(bool can_have_scrollbars) {
1938 if (FrameView* view = GetFrameView()) 1910 if (FrameView* view = GetFrameView())
1939 view->SetCanHaveScrollbars(can_have_scrollbars); 1911 view->SetCanHaveScrollbars(can_have_scrollbars);
1940 } 1912 }
1941 1913
(...skipping 660 matching lines...) Expand 10 before | Expand all | Expand 10 after
2602 2574
2603 TextCheckerClient& WebLocalFrameImpl::GetTextCheckerClient() const { 2575 TextCheckerClient& WebLocalFrameImpl::GetTextCheckerClient() const {
2604 return *text_checker_client_; 2576 return *text_checker_client_;
2605 } 2577 }
2606 2578
2607 void WebLocalFrameImpl::SetTextCheckClient( 2579 void WebLocalFrameImpl::SetTextCheckClient(
2608 WebTextCheckClient* text_check_client) { 2580 WebTextCheckClient* text_check_client) {
2609 text_check_client_ = text_check_client; 2581 text_check_client_ = text_check_client;
2610 } 2582 }
2611 2583
2584 WebPluginContainerBase* WebLocalFrameImpl::CurrentPluginContainer(
2585 LocalFrame* frame,
2586 Node* node) const {
dcheng 2017/05/19 09:07:02 From what I can tell, there are no callers that pa
slangley 2017/05/21 23:53:33 There is one caller that passes a Node - "WebLocal
2587 DCHECK(frame);
2588 return frame->GetWebPluginContainerBase(node);
2589 }
2590
2612 } // namespace blink 2591 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698