WebCore:

        Reviewed by Darin.
        
        Fix <rdar://problem/5480050>
        Leopard9A551 with Dashcode 112: Dashcode crash when dragging image into canvas.
        
        If @import stylesheet was modified through CSS DOM style selector would not get updated. This
        could lead to crashes.

        Test: fast/css/import-style-update.html

        * css/CSSStyleSheet.cpp:
        (WebCore::CSSStyleSheet::styleSheetChanged):

LayoutTests:

        Reviewed by Darin.
        
        Test for <rdar://problem/5480050>
        Leopard9A551 with Dashcode 112: Dashcode crash when dragging image into canvas.
        
        Non-crashing test case, but it demonstrates the same problem that would crash
        under some circumstances.

        * fast/css/import-style-update-expected.txt: Added.
        * fast/css/import-style-update.html: Added.



git-svn-id: http://svn.webkit.org/repository/webkit/trunk@25598 268f45cc-cd09-0410-ab3c-d52691b4dbfc
diff --git a/WebCore/css/CSSStyleSheet.cpp b/WebCore/css/CSSStyleSheet.cpp
index 63fd21b8..2685185 100644
--- a/WebCore/css/CSSStyleSheet.cpp
+++ b/WebCore/css/CSSStyleSheet.cpp
@@ -190,12 +190,17 @@
 
 void CSSStyleSheet::styleSheetChanged()
 {
+    StyleBase* root = this;
+    while (StyleBase* parent = root->parent())
+        root = parent;
+    Document* documentToUpdate = (root && root->isCSSStyleSheet()) ? static_cast<CSSStyleSheet*>(root)->doc() : 0;
+    
     /* FIXME: We don't need to do everything updateStyleSelector does,
      * basically we just need to recreate the document's selector with the
      * already existing style sheets.
      */
-    if (m_doc)
-        m_doc->updateStyleSelector();
+    if (documentToUpdate)
+        documentToUpdate->updateStyleSelector();
 }
 
 }